I am using JavaScript and jQuery for my web application. In one case I have used the ternary operator in order to optimize the code while assigning object values.
I have manually set the
d
d=true;
var args = { d ? { target:"div"} : {main:"body"}, status:"enabled", updated:"yes" };
Thats incorrect JavaScript syntax, You cant dynamicaly define properies on object this way. You can do this:
var args = {status:"enabled", updated:"yes"};
d ? (args.target = "div") : (args.main = "body");
In ES2015 you can do:
var args = {[d ? "target" : "main"]: d ? "div" : "body", status:"enabled", updated:"yes"};