From this question: What does "var FOO = FOO || {}" (assign a variable or an empty object to that variable) mean in Javascript?
I've learned that var FOO = FOO || {}
essentially means "If FOO exists, then leave it untouched, else make it an empty object".
But how?
This is how I would parse this syntax:
var FOO = (FOO || {})
So: If FOO
exists AND evaluates to Boolean value of True, then (FOO || {})
will return True, so eventually FOO
will be completely overwritten and will hold the Boolean value of True from now on.
Else (FOO || {})
will return to whatever Boolean value {}
evalueates to. Since an empty object, which {}
is, always evaluates to True...
Then in ANY case (FOO || {})
should evaluate to True, so...
In ANY POSSIBLE CASE, after evaluating var FOO = FOO || {}
, FOO should hold the trivial Boolean value of True, regardless of whatever it was holding before. Essentially, to my understanding, var FOO = FOO || {}
should be equivalent to var FOO = True
.
Where is my mistake?