JavaScipt Execution Context

How JS code is executed?

Everything in JavaScript happens inside an "Execution Context"

Execution Context

As soon as the JS program is run, the global execution context is created. It has 2 components, Memory & Code, so it is created in 2 phases.

Phase 1

Memory creation phase. In the memory creation phase, we allocate memory to all variables & functions inside global space. It allocates variables with the value of undefined & in functions, it just copies the whole code of the function.

Phase 2

Now all JS program is executed line by line it goes to the variable & replace it with the given value. & similarly, it will now invoke the function & goes to the next variable & it will invoke the function