๐ฐclosure
JS โฉ value โฉ function โฉ closure
A closure
is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment).
gives you access to an outer function's scope from an inner function.
is created every time a function is created, at function creation time.
๐ lexical environment
A closure is a function that remembers its outer variables and can access them. in JavaScript, all functions are naturally closures (with only one exception ๐ "new Function" syntax). ๐ JS.info โฉ Closure
it matters from which scope your closure closes in variables.
๐ scopes matter with closuresโ
้่ชชไผผไนๆไธๅๅฅๆช็ "for-init" scope๏ผไฝ่ฃก้ข let ่ฎๆธ็่กจ็พๅ ถๅฏฆๆดๅๆฏ block-scopedใ๐ scopes matter with closures โฉ โ
Closure is observed when a function uses variable(s) from outer scope(s) even while running in a scope where those variable(s) wouldn't be accessible. ๐ You Don't Know JS Yet
closure: manage grades - closure can be used as a function with private properties.
closure as object - closure can be used as an object.
lexical environment - stores all local variables.
[[Environment]] - reference to surrounding lexical environment.
replit๏ผclosures
a closure is usually a nested function.
Last updated