JavaScript “Scope & Closure”
[JL’s Coding Bootcamp Story] Series
JavaScript “Scope & Closure”(Current)
JavaScript “This”
JavaScript “Call, Apply, Bind”
Summary of CodeSchool’s “Try jQuery”
JavaScript “This” — Advanced
JavaScript “Code Reuse” — Part 1–1: Decorators
JavaScript “Code Reuse” — Part 1–2: Functional Classes
JavaScript “Prototype Chains”
JavaScript “Code Reuse” — Part 2–1: Prototypal Classes
JavaScript “Code Reuse” — Part 2–2: Pseudo-classical Classes
#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.
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👏