When our program is loaded into the memory, it starts execution from the first function call which is foo ()
Hence, the first stack entry is foo (). Since foo function calls bar function, secondly stack entry is a bar (). Since bar function calls baz function, thirdly stack entry is baz(). And finally, baz function calls console.log; fourth stack entry is console.log (‘Hello from baz’).
Until a function returns something, it won’t be popped out from the stack. The stack will pop entries one by one as soon as the entry returns some value, and it will continue pending function executions.
Want to receive a fortnightly round up of the latest tech updates? Subscribe to
our free newsletter. No spam, just insightful content covering design,
development, AI and much more.