var Statement
JavaScript allows var
definitions to occur
anywhere within a function. JSLint is stricter.
JSLint expects that:
A
var
will be declared only once, and that it will be declared before it is used.A function will be declared before it is used.
Parameters will not also be declared as
var
s.
JSLint does not expect:
The
arguments
array to be declared as avar
.That a variable will be declared in a block. This is because JavaScript blocks do not have block scope. This can have unexpected consequences, so define all variables at the top of the function body.
Get JavaScript: The Good Parts now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.