4 ms·
js also doesn't behave as you want: var a = 9; function foo() { console.log(a); var a = 12; } foo(); $node foo.js undefined The sa
by h8hawk 7y ago
js also doesn't behave as you want:
var a = 9;
function foo() {
console.log(a);
var a = 12;
}
foo();
$node foo.js
undefined
The same goes with ruby.
- xscott 7y agoJavaScript is far from perfect, but at least it's clear you declared two variables.
- jakear 7y agoYou’re sidestepping the problem. The problem is that Python uses the same syntax for variable declaration and variable assignment, and this can lead to unexpected behavior. That’s far from normal in the programming world, making it more unexpected.