What is lexical scope?

Functions have lexical scope in Javascript.
This means that the scope of a function is created when it is defined, not when it is executed (runtime).

Example:

<script type="text/javascript">
function calculateArea(){ return width*height; }
function getVolume(length){
var width = 9, height = 2;
return length*calculateArea();
}
/* One might think that calculateArea () has access to the width and height
variables when it is executed inside the getVolume (). This is not the
case as both function are define in the global scope. *//* To get it to what we want, we can rewrite this to: */function getVol(length){
var width = 9, height = 2;
function calcArea(){ return width*height; }
return length*calcArea();
}
alert(getVol(4));
// alert(getVolume(4)); // will not work
</script>

What is NOT a local scope.

Any block of code surrounded with the {} symbols define NOT a local scope, as in many other languages.