Scope Chains

Exploring a Nodeschool tutorial about Lexical Scoping in Javascript.

This morning I had a few minutes to try another nodeschool tutorial concerning scope chains. This tutorial looks very brief, but contains some important concepts, especially for programmers who are new to Javascript.

The two main types of scoping covered by the tutorial are Lexical Scoping and Block Scoping. Here is a quick example from part of the tutorial, that lays out what is to be covered:

LEXICAL SCOPING

function someFunc() {
var aVariable;
}

aVariable is LEXICALLY SCOPED within someFunc.

BLOCK SCOPING

if (true) {
let aVariable;
}

aVariable is BLOCK SCOPED within the if’s curly braces.


Daniel Paul Grech Pereira is a computer programmer in Toronto, Canada.

LinkedIN — Twitter — YouTube