Can I write an if statement within a Javascript object when setting an attribute?

javascript

Solution

No, however you can use the ternary operator:

var testBoolean = true;

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

Problem

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" }, } ```

Original source