3 ms·
"Assigning a value to an undeclared variable implicitly creates it as a global variable (it becomes a property of the global object) when the assignment is exec
by sbuttgereit 10y ago
"Assigning a value to an undeclared variable implicitly creates it as a global variable (it becomes a property of the global object) when the assignment is executed."
From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- Animats 10y agoRight. This is a typical language design mistake. It happens in phases: - "We're not going to have declarations in our language. First use defines a variable". - "We need some way to define local variables. But if we make that the default, existing code will break. So the default has to be global." - Embrace the pain. There are variants on this theme. Python is local by default. Go has variable creation by assignment with ":=", but with weird semantics for multiple assignment. Other classic mistakes are "we don't need a Boolean type; 1 and 0 are enough", and "there's only one kind of integer". Fixing those later always sucks.