Before we get started, there’s a couple of concepts you’ll need to be familiar with to really wrap your head around Execution Contexts: Scopes and Closures. If you’re not familiar with these, or just want to brush up, check out my previous two articles in this series:
- Global Execution Context
This is where the interpreter starts, it’s the default execution context. Two things are always done here, first it creates a global window object and second, it sets the binding of the keyword ‘this’ to that global window object!
- Function Execution Context
Whenever a function is *invoked* a new execution context is created! This means that every function has it’s own execution context, even nested functions!
The Call Stack
This concept can really trick up beginners. It works on a last-in first-out system (LIFO) which can be confusing. An easy way to think of it is as a stack of plates in a restaurant. Each time the dishwasher finishes cleaning a plate, he puts it on top of the stack, and each time the chef needs to use a plate, he grabs one from the top of the stack!
You might be wondering how we’re able to invoke
There’s essentially two phases:
- The Creation Phase
undefined but once we get to the second phase that’ll be fixed!
2. The Execution Phase
Well I hope this was helpful in getting your head wrapped around Execution Contexts, and if you read my other articles I sincerely hope you’ve got a more solid grasp of Scopes and Closures as well! Thanks for reading!