Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  25] [ 5]  / answers: 1 / hits: 55172  / 11 Years ago, tue, february 4, 2014, 12:00:00

Setting attributeTwo using an if statement. What is the correct way to do this?



var testBoolean = true;

var object = {
attributeOne: attributeOne,
attributeTwo: if (testBoolean) { attributeTwo } else { attributeTwoToo },
}

More From » javascript

 Answers
33

No, however you can use the ternary operator:



var testBoolean = true;

var object = {
attributeOne: attributeOne,
attributeTwo: testBoolean ? attributeTwo : attributeTwoToo
}

[#72722] Monday, February 3, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alvin

Total Points: 55
Total Questions: 101
Total Answers: 109

Location: Sudan
Member since Tue, Aug 3, 2021
3 Years ago
;