JavaScript allows vars to be declared and used
anywhere in a function
while (foo()) {
var bar = 4;
…
}
return bar;
but this is confusing to programmers used to block-scoped languages.
To make this go away, make sure the var is declared in a
block containing all uses, as in
var bar;
while (foo()) {
bar = 4;
…
}
return bar;
One of the least controversial parts of the proposed EcmaScript 4,
was it's introduction of a block scoped
let
statement to eventually replace var, so getting in the
practice of block scoping will pay off in the future.
As always, to turn this off, put the error message name
OUT_OF_BLOCK_SCOPE in the