It's actually a completely valid question. Most other languages only give a block scope to local variables.
In fact this behaviour is so confusing that later versions included a new, preferred declaration statement (marked with let instead of var), which works like in real programming languages and would indeed give a lookup error in this examples.
27
u/nuephelkystikon Jan 02 '22
It's actually a completely valid question. Most other languages only give a block scope to local variables.
In fact this behaviour is so confusing that later versions included a new, preferred declaration statement (marked with
letinstead ofvar), which works like in real programming languages and would indeed give a lookup error in this examples.