004-Scope Chain
004-Scope Chain
Scope Chain
EHSAN EHRARI
Expressions in Scope Chain
• Scooping
• Lexical Scooping
• Scope
• Scope of a Variable
Scoping
1.Global scope: Variables declared outside of any functions or blocks have global
scope, which means they can be accessed from any part of the program,
including inside functions and blocks.
2.Local scope: Variables declared inside functions or blocks have local scope,
which means they can only be accessed within the function or block in which they
are declared.
3.Block scope: Starting from ES6 (ECMAScript 2015), JavaScript introduced the let
and const keywords for declaring variables. Variables declared with these keywords
have block scope, which means they are only accessible within the block in which
they are declared, including any nested blocks.
Example
Scope of a Variable