HOW JAVASCRIPT WORKS AND EXECUTION CONTEXT

https://www.youtube.com/watch?v=iLWTnMzWtj4&list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP&index=3&ab_channel=AkshaySaini

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/673a6c18-ec0a-4802-8281-76ed801239be/Screenshot_2020-12-24_125138.jpg

But as it hits the line number 6 there is a function invoke so now JS makes a new execution context think of it as a sub process inside a global process and yes it is a execution context inside a global execution state. So this new execution will do all the things we discussed that is memory creation and code execution for the function.

When the function hits return state it tells the code to go and hit the execution of the next line in the code. And as soon as the return hit hit it will delete the execution context of the function.

Finally after hitting the return statement of the last function it will delete the execution context of the function after all the code is executed it will also delete the global execution context

Phase 1: Memory Creation Phase

Phase 1: Memory Creation Phase

Phase 2: code execution - When the fist function is invoked

Phase 2: code execution - When the fist function is invoked

Final Function execution

Final Function execution