Lexical Scope

The very first section of the Udacity Object-Oriented JavaScript course was about Scopes and Closures. ┬áStarting with Lexical Scope, below is my summary of the first lecture to me it makes sense, however I’m aware that it may not to you the reader and if you have any questions or suggestions then please send them.

There are regions in the source code where you can refer to variables without getting access errors. This can be best understood without even running code. As it only concerns areas of code where different variable names have meaning.

In simple programs with no functions, there is only one scope – the global scope. In some JavaScript environments, global scope is shared across different files, as a way for any part of the program to interact with another part.

A variable added here is in the global scope and therefore accessed from anywhere in the whole program.

After defining a variable in the lexical scope, you can reference to that variable anywhere in the lexical scope.

Leave a Reply

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