What is the difference in performance and reliability of the following variable assignments:
var obj = {name: "Antonia"};
var foo = obj.name ? obj.name : "foo";
var baz = obj.name || "baz";
Since obj.name is defined, both foo and baz will contain "Antonia".
As far as I know, the code should behave the same for obj.name values other than null, undefined, 0 and false. If the property is set to one of those values foo will contain "foo" and baz is assigned "baz".
Is there some kind of drawback I'm missing? Which one do you recommend to use?
Thanks!
PS: fiddle to play aroud https://jsfiddle.net/a2rgvhzm/