🔰scope
🚧 under construction
JS ⟩ scope
( visibility of variable)
the current context of execution in which values and expressions are "visible" or can be referenced.
concepts about scopes
lexical environment - stores local variables/functions/this.
kindes of scopes
top-level scope - the scope of a JS file.
global scope: default scope for all code running in script mode.
module scope: scope for code running in module mode.
function scope: scope created with a function.
block scope:scope created with a pair of curly braces. (where let / const can belong to)
special scopes
function name scope - where name of function expression lives in.
"for-init" scope - where the for loop initialization variables live in.
scopes are
determined at compile-time.
but (lexical environment) created at runtime, each time a scope is entered.
but in sloppy mode, you can modify scope (I think the term "scope" is not quite accurate, maybe lexical environment❓) at runtime. ( 👉 modify current scope at runtime❗️❗)
雖說似乎有一個奇怪的 "for-init" scope,但裡面 let 變數的表現其實更像是 block-scoped。👉 scopes matter with closures ⟩ ❓
scopes are determined at compile-time.
scopes are created at runtime.
in strict mode, script in eval has its own scope.
closure ... 🚧
Last updated
Was this helpful?