Are there any pitfalls to var something = something || {}
- by puk
I came across this answer where the poster suggested that the shorthand for
if(typeof MyNamespace === 'undefined'){
var MyNamespace = {};
}
is
var MyNamespace = MyNamespace || {};
Would veteran programmers recommend the latter to simplify the code, or does it overly complicate things, like abusing ++ or -- in complex compound statements?
EDIT The reason I asked is b/c a while back someone inspired me by pointing out that a lot of the people who think they are expert programmers make a lot of beginners mistakes. The case at the time was
if (isReady){
//Do Something
}
And what he was saying is that a condition should mean something, isReady doesn't 'mean' anything, instead, we should use
if (isReady === true){
//Do Something
}