3 ms·
`var` creates global properties when used in the global scope, which is useful at times.
by DaiPlusPlus 7y ago
`var` creates global properties when used in the global scope, which is useful at times.
- neurotrace 7y agoIf you really, really need a global then you should assign it to `window/global/globalThis` instead of relying on the weird behavior of `var`
- wolco 7y agoWhat do you find weird about var?
- DaiPlusPlus 7y agoIt's weird because it has side-effects (namely, implicitly adding/setting a named property in the current scope object, if any). It means that a top-level script using `var` that is subsequently refactored into a scoped function somewhere will now have different semantics and might break if other code depended on `var` creating a new global property.