The Declaration Phase (Memory Allocation Phase): During this phase, memory is allocated for variables and functions. For variables, memory is reserved, and the value "undefined" is assigned to them. Functions, on the other hand, have their entire function bodies stored in memory. Once all variables and functions have been allocated memory, the next phase begins.
The Code Execution Phase: In this phase, the code is executed, starting from the first line and progressing line by line. Variables that were initially assigned "undefined" are then replaced with their actual values. When encountering a function, a new execution phase is created and added to the call stack. Memory allocation is performed, followed by code execution within the function. Once the function completes its task and returns a value, or if it is a void function with no return value, it is removed from the call stack. This process continues until all variables and functions have been executed. Finally, the global execution context is removed from the call stack, and the execution comes to an end.