[ ] Please close this issue, I accidentally submitted it without adding any details
[ ] New documentation
[x] Correction or update
Details
The article says
When calling bar, a first frame is created containing bar's arguments and local variables. When bar calls foo, a second frame is created and pushed on top of the first one containing foo's arguments and local variables.
Conceptually, at least, the arguments and local variables in JS don't sit directly on the stack as they do in C, for example, but in an execution context which is referenced by a pointer in the stack frame, but which is actually allocated on the heap. That's how they can be accessed by nested functions long after the outer function has returned.
I suppose that some runtimes may optimize this behavior by first allocating the variables directly on the stack and then copying only the ones that are used by nested functions to a new execution context, but since this is a very high-level overview of the subject, wouldn't it be better not to give readers the false impression that the JS stack works exactly like the stack in C?
Request type
Details
The article says
Conceptually, at least, the arguments and local variables in JS don't sit directly on the stack as they do in C, for example, but in an execution context which is referenced by a pointer in the stack frame, but which is actually allocated on the heap. That's how they can be accessed by nested functions long after the outer function has returned.
I suppose that some runtimes may optimize this behavior by first allocating the variables directly on the stack and then copying only the ones that are used by nested functions to a new execution context, but since this is a very high-level overview of the subject, wouldn't it be better not to give readers the false impression that the JS stack works exactly like the stack in C?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop