Does JavaScript create a new execution context when executing a block to associate the its lexical environment with it.
-
Check section "13.2.14Runtime Semantics: BlockDeclarationInstantiation" in ecma-international.org/ecma-262/8.0/…Mörre– Mörre2017-10-01 18:12:30 +00:00Commented Oct 1, 2017 at 18:12
-
Are you referencing a block outside of a function call or a block within a function call?guest271314– guest2713142017-10-01 18:45:06 +00:00Commented Oct 1, 2017 at 18:45
1 Answer
No. An execution context is essentially a call stack frame, while the lexical environment is the current scope. No function gets called when a block is evaluated.
You can read in the specification for the evaluation semantics of blocks that it creates a new lexical environment (initialised with the variables in the block scope) that has the old environment as its parent, and "Set[s] the running execution context’s LexicalEnvironment to [that value]". After executing the statements in the block, the child environment is popped off again, but the running execution context did stay the same all the time.
7 Comments
function, it's whatever scope the block is found in.