JavaScript allows var
s to be declared and used
anywhere in a function
but this is confusing to programmers used to block-scoped languages. To make this go away, make sure thewhile (foo()) { var bar = 4; … } return bar;
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 ignores list.