Execution Context (Creation)
Reminder: this is still before your code is being executed. At this point in time, the memory set up for your variables and functions doesn’t have access to those values until the code is executed. All variables at the creation of the global execution context are set to undefined.
Execution Context Stack
Now we get to the second phase where your code is actually ran. This is where the JS engine gains access to all the variables within the variable environment, and starts something called the stack. Every time the JS engine reaches a function call or invocation a new function execution context is created where ‘this’, the variables and functions, and objects are all related to that function context. With every function call the stack grows larger with the current function being executed at the top of the stack. Here we can see an example:
Here you visually see the stack as the Global Execution Context is created and executed, and each function call that follows is added to the stack(function a, function b). The keyword ‘this’ will have a different context depending on which function is at the top of the stack. If you would like to read further on this click here.
In the next blog I will cover another under the hood concept for you guys!
P.S ( I am taking a Udemy course so I will choose whatever topic I am currently learning about next week!)