effects/animation, and the
Hooray! you have now learned something that most developers don't know about.
Service Worker in the browser and
When I am saying it is synchronous single-threaded language, it means only one line can be executed in JS Engine at a time in a specific order.
What is Execution Context?
So now let us think about when we run any code. what could be the possible actors involved?
- Maybe memory will be initialized.
- Code will be stored somewhere in memory.
- There will be a JS code running somewhere.
So, yes! we have our answers.
Execution Context is composed of?
Execution Context is composed of two parts,
Memory ComponentAlso known as Variable Environment. Inside the memory component, all objects including variables, functions, and whole code are saved in form of key-value pair
Code ComponentAlso known as a thread of execution. (It runs JS code line by line while referring to variable/function values from
When we talk about Execution context, there are 3 types of the Execution context. I will try not to go into much detail but would like to give an overview.
Types of Execution Context
Global Execution Context
This is the default or base execution context. The code that is not inside any function is in the global execution context. It performs two things: it creates a global object which is a window object (in the case of browsers) and sets the value of
thisto equal to the global object. There can only be one global execution context in a program. Once the whole JS code is executed,
Global Execution Contextis destroyed.
Functional Execution Context
Every time a function is invoked, a brand new execution context is created for that function and adds it to the call stack. Each function has its own execution context, but it’s created when the function is invoked or called. There can be any number of function execution contexts. Once function iteration is completed. The execution context is then destroyed. and that execution context can be removed from the call stack.
Eval Function Execution Context
So stay tunned! and Happy learning.