Execution Context & Call Stack

1 min read
How JavaScript Code Executes
JavaScript uses a single-threaded model with an event loop. It executes code in two phases:
Creation Phase: Memory allocation for variables and functions.
Execution Phase: Runs the code line by line.
Example:
jsCopyEditconsole.log("Start");
function greet() {
console.log("Hello!");
}
greet();
console.log("End");
โ Execution Order:
"Start"
prints.greet()
is called, and"Hello!"
prints."End"
prints.
๐ Call Stack Visualization:
console.log("Start")
โ Pushed & executed.greet()
โ Pushed, executesconsole.log("Hello!")
, then popped.console.log("End")
โ Pushed & executed.
0
Subscribe to my newsletter
Read articles from Kailash Gayari directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by