One of the fundamental aspects of Javascript is variable scope, and in this lesson we'll dive into how variable scope works when defining variables with var
, let
, or const
.
The three main takeaways are:
Inner scope can always read values defined in an outer parent scope.
Outer scope cannot read values defined in an inner scope (except when defined with var
).
The var
scope-bleed issue can be overcome using immediately-invoked function expressions (IIFEs).