3 ms·
The rules for var and "hoisting" are so horrible that let and const are a justified language complication; now JavaScript variable scoping is decently usable. O
by HelloNurse 6y ago
The rules for var and "hoisting" are so horrible that let and const are a justified language complication; now JavaScript variable scoping is decently usable. On the other hand, Python can afford to spend its language complication budget on something more useful than specialized mechanisms to end variable scope.
Since JavaScript tends to have many more unnamed functions defined in the middle of long functions, compared to Python (which tends towards named functions, classes, or comprehensions), block scoped variables (or more precisely simple and rigorous rules about scoping) are much more useful and important in JavaScript than they would be in Python, since if there is a part of a Python function where some variable shouldn't be visible it's probably a long and complex function which can and should have its variable scopes refactored apart.