Variable Access – Lexical Scope 2

The very next part following on from Lexical Scope is variable access.  Below is what I took away from this section.

A new lexical scope is created every time a function definition is typed i.e function(){ };

The curly braces around the functions body enclose an area of code where different access rules apply, a different lexical scope. A new inner lexical scope with variables is more limited than the outer lexical scope.

If an inner variable is accessed from outside that scope an error will be registered

var hero = aHero(),
var newSaga = function() {
var foil = aFoil();
log (foil);

All the following variables are available inside the newSaga function.

Leave a Reply

Your email address will not be published. Required fields are marked *