O'Reilly logo

JavaScript: The Good Parts by Douglas Crockford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 vars.

JSLint does not expect:

  • The arguments array to be declared as a var.

  • 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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required