DEV Community

Mohammed Salah
Mohammed Salah

Posted on

javascript exeuction context

javascript execution context
That is, execution context in JavaScript
The first means an environment in which the code is executed, and in order to imagine it, we put in our minds that it is a large container that contains something that we can use, for example, variables.

Inside the large container, we may have small containers. Each container, of course, contains the code that will be executed, and with the code there are also the needs that the code may need in order to execute, as well as the variables.

There is something that manages this

This engine provides JavaScript, which varies from browser to browser

When the JavaScript engine receives the code, it downloads it and starts creating a code tree

It starts to work automatically on the large container that we talked about, and it contains every thing in the code and every thing that the code can need.

If you tried to debug the browser and it got a breakpoint

The debug will of course start from breakpoint and will remain, for example, function

While you are monitoring the stack we talked about, you will find that put the global execution context in the stack

Then creates something called the Function Execution Context for the function, which is a breakpoint.

This is the small container we talked about

But apart from debug, every invoke function is executed by an execution context

This means that every caller on a function, this function creates an execution context in which the code for the function and anything needed in the function.

There is another execution context called eval function execution context, and this is executed when the engine finds the breakpoint called eval()

Where do these context exeuctions go to be implemented?

When the engine finds a function, it creates the execution context for this function

Then he puts it in the stack to be executed

Of course, the global execution context is created automatically and placed in the stack first

This is a simplified explanation of the execution context

Image description

Top comments (0)