I am just curious. How exactly are JavaScript engines internally implementing the EMCAScript execution stack instructions.
If you look at the code below, ECMAScript will expect us to create a Global execution context with an Environmental Record that will contain the fun1, res and c variables. When fun1 is invoked, we will then create a new function execution context which will have an Environmental Record that will contain the a and b variables and associated values.
In this blog post from the V8 team Blazingly fast parsing, part 2: lazy parsing, it is clear that internally they are using the memory stack to control function invocations unless variables are affected by closure.
I am curious if the res and c variables in the code below will be placed on the stack as well? Will environmental records for the global and function execution context actually be created for a simple code like the one in the example.
Any answers will be appreciated, fully understanding that the answer in this case ultimately does not matter as far as use of JS is concerned.
let fun1 = function(a){
let b = 2;
return a+b;
}
let res = fun1(4);
let c = ”done";