Execution Context in JS

·

2 min read

In JavaScript, an execution context is the environment in which JavaScript code is executed. It includes the following:

  • The variables and functions that are accessible to the code.

  • The value of the this keyword.

  • The code that is currently being executed.

To understand this in easy language let's Imagine the execution context in JavaScript as a little bubble or container where your code runs. It's like a mini-universe for your code to live in.

Every time your code is executed, whether it's a function or just regular code, it gets its own bubble (execution context) to work in. This bubble keeps track of things like variables, functions, and where they are located in your code. It also knows what other bubbles (execution contexts) are around it.

When a function is called, a new bubble is created just for that function, and it knows about the bubble where it was called from. Once the function finishes running, its bubble disappears, and the code goes back to the previous bubble (the one where the function was called from).

This system of bubbles (execution contexts) helps JavaScript keep everything organized and separate, so your code doesn't get mixed up and confused. It's like having little containers for different parts of your code, each with its own stuff neatly organized inside

Thank you for reading, please follow me on Twitter, i regularly share content about Javascript, and React and contribute to Opensource Projects

Twitter-https://twitter.com/Diwakar_766

Github-https://github.com/DIWAKARKASHYAP