Please enable JavaScript.
Coggle requires JavaScript to display documents.
Variable scope, closure, Variable scope, closure - Coggle Diagram
Variable scope, closure
Lexical Environment
Step 1. Variables
A “variable” is just a property of the special internal object, Environment Record. “To get or change a variable” means “to get or change a property of that object”.
-
-
-
-
-
-
-
Theory
Garbage collection
a Lexical Environment is removed from memory with all the variables after the function call finishes.
-
Real-life optimizations
They analyze variable usage and if it’s obvious from the code that an outer variable is not used – it is removed.
Code blocks
a variable is declared inside a code block {...}, it’s only visible inside that block.
-
-
let
-
limited in scope to the block, statement, or expression on which it is used
-
-
-
Hoisting
variables, function declarations and classes are moved to the top of their scope before code execution.
Remember that JavaScript only hoists declarations, not initialisation
note
-
-
-
cannot use the reserved words as variables, labels, object or function names
-
-