|
|
|
|
|
by mici
3173 days ago
|
|
Great article! A few things have caught my eye: > MyApp.users = MyApp.user || {}; Is this a typo, or intentional? If it is intentional, can someone explain the thought behind it? Also, in some examples Medium (or the author's text editor) seems to have changed apostrophes and quotation marks, this makes the examples harder to try. |
|
It's just to not accidentally set a already defined foo as an empty object incase foo is already defined. Yeah... JavaScript...
Another common idiom:
The || (logical OR) can be used for setting a default incase the value before it is falsey (null, undefined, false...).