Javascript is one of the most used and popular languages in the world.But there is also a quote which is very famous for the javascript language.
"Javascript is the most love and hate language in the world".
but why it is so scary for people, most developers do not how javascript works that why it is hated by the developer let talk about how javascript works.
How code executes in javascript
compilation phase
The compilation phase is the first phase of the javascript execution . In the compilation phase, there is also 3 sub-phase that are done for the error-free clean code for execution.
Don't worry nobody asks about this compilation phase for interview purposes. Lets move ahead and talk about the real one
Global execution context
Global execution context is the place the execution starts in the javascript or you can say after the error-free code all the things lie in the global execution context.
Global execution context consists of two-phases
Memory creation phase
code execution phase
Memory creation phase
The memory creation phase is the first phase of javascript here memory is allocated to all the variables and functions in the javascript. For a variable, it allocated one special placeholder called undefined is allocated and for a function, it stores the whole function as it defines in the code.
Code execution phase
the code execution phase is the second phase where we give the value to the other variables and execute it one by one.
the code execution lies in the single-thread Synchronous programming language.