๐ฐ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?