#Scope

What is a scope? A scope is a part of a program where a binding between a variable and value is valid. Variables are only available under certain circumstances. Different languages have different access rules.

№1 Use of the word “scope” — Lexical(Static) : This use of the word scope describes the regions in your source code where you can refer to a variable by name without getting access errors.

COPYRIGHT © 2018 CodeStates

1. Local Variable : Function Level

2. Global Variable

3. Hoisting

Hoisting is “JavaScript’s default behavior of moving all declarations to the top of the current scope (to the top of the current script or the current function).” (W3Schools)

#Closure

A closure is “the combination of a function and the lexical environment within which that function was declared.” (MDN)

Closure has 3 types of scope chains : 1. Access to closure itself 2. Access to variables outside of a function 3. Access to a global variable.

№2 Use of the word “scope” — In-memory : When a program runs, it builds up storage systems for holding variables and their values. These in-memory scope structures are called “execution contexts.”

[Note] This blog post is written based on a lecture from CodeStates.

Thanks for reading! 💕 If you like this blog post, please clap👏

--

--