Understanding the "|| {}" construct in javascript
javascript, redefinition, scope
Solution
You are correct. If the variable already exists (ours or not), don't change it. If it doesn't exist, let's create a new one.
Problem
Possible Duplicate: What does “var FOO = FOO || {}” mean in Javascript? Javascript - Can you add condition to variable declaration I believe this has to do with scoping, and not redefining scope. I see a lot of this in popular javascript frameworks: ``` var something = something || {}; ``` Is that to do with not accidentally redefining a top-level variable?
Related problems
- What does "var FOO = FOO || {}" (assign a variable or an empty object to that variable) mean in Javascript?
- Can you add a condition to a variable declaration?
- What does "var FOO = FOO || {}" (assign a variable or an empty object to that variable) mean in Javascript?
- Can you add a condition to a variable declaration?