JavaScript - Block Scope

javascript

A block is a set of statements wrapped in curly braces.  Unlike many other 
languages, blocks in JavaScript do not create a new scope.  In fact, all variables
and functions are hoisted to the top of the function that they are declared in, 
and this may create problem / confusion.  See a separate page for problems
related to hoisting.

JavaScript does not have a concept of "block scope".  Blocks in JavaScript do 
not create new scopes.  A block is a set of statement wrapped in curly braces. 
Unlike many other languages, blocks in JavaScript do not create a new scope, so 
variables should be defined at the top of the function, not in blocks. 
See "JavaScript: The Good Parts" by Douglas Crockford, page 10.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License