2. Scope 1
What is Scope?
We'll borrow from Kyle Simpson and say that, "Scope is a well-defined set of rules for storing variables in some location, and for finding those variables at a later time."
Since we've already talked about LHS and RHS lookups, identifying scope should be fairly easy since it can basically be boiled down to the process of answering the question, "what is this variable referencing?".
How is Scope Created?
Until rather recently, the only thing that created scope in JavaScript
were functions. But as we've already seen, any block {}
can
create scope, so long as the variables within that block are created using
let
or const
. But let's start ES5 style and look
at some examples of scopes with functions.