Can I write an if statement within a Javascript object when setting an attribute?
No, however you can use the ternary operator:
var testBoolean = true;
var object = {
attributeOne: "attributeOne",
attributeTwo: testBoolean ? "attributeTwo" : "attributeTwoToo"
}
You can use an if statement, if it is within a immediately invoked function.
var x = {
y: (function(){
if (true) return 'somevalue';
}())
};