0

Is function's lexical scope created in "compile time" of that function's area(if that function is declared in the global area, this area is the global area), or "evaluation time" of that function, or "execution time" of that function? Which of these? I've already known that the [[Environment]] internal slot is defined in compile time, and when a function is executed, that function's lexical environment refers to the [[Environment]]. So I think that a function's surrounding state is allocated in compile time of a function's area. According to this, a scope of outer environment is created in 'compile time', and a scope of inner environment(environmentRecord) is created in 'execution time' of that function, I think. Is it correct?

vriznet
  • 3
  • 3
  • 1
    This is an implementation detail. – Barmar Jul 01 '21 at 17:09
  • There is (conceptually) no "compile time" for JavaScript. It's an interpreted language. There are interpreters that have a compilation step included but they aren't the standard. Also, the compilation step would be transparent in terms of logical operations that happen. As in, the compilation will not change the result of something that happens, at best it changes the speed. – VLAZ Jul 01 '21 at 17:20
  • @Barmar Could you explain an implementation detail more? – vriznet Jul 02 '21 at 02:04
  • 1
    An implementation detail is something that depends on how the JavaScript interpreter/compiler is written, not something required by the language or visible to application code. The JavaScript programmer can do it however they way as long as the required result is obtained. – Barmar Jul 02 '21 at 02:06
  • @VLAZ If there is no 'compile time', what we have to call 'the phase(step) of collecting an information of variables that is in an execution context'? (which causes hoisting) – vriznet Jul 02 '21 at 04:16
  • @vriznet it's part of executing the code. The strategy is known as a two-pass interpreter - the first pass will read the file and prepare for execution (this is when hoisting happens - the preparation includes creating variables, as well as syntax checks), then the second pass is the traditional "read and execute line by line" interpreter behaviour but it would also be be using the preparation. – VLAZ Jul 02 '21 at 04:50
  • @VLAZ Thanks for reply, and I understood. So could you please tell me when is a function's lexical scope created? ('preparing time' or 'execution time' by interpreter) – vriznet Jul 02 '21 at 07:57
  • @Barmar Thank you. So if you know about V8 engine's behavior, please tell me when is a function's lexical scope created, assuming that interpreter/compiler is V8. – vriznet Jul 02 '21 at 07:59

0 Answers0