Synchronous calls and execution stack
How it works
An ordinary synchronous function call runs until it returns or throws. Nested calls create execution contexts on the conceptual stack; the caller resumes after the callee completes. A queued callback cannot interrupt the current synchronous call simply because its promise is already fulfilled. Execution-context stacks are specification concepts, not a guarantee about physical engine stack frames.
Example 1
function inner() { console.log("inner"); }function outer() { console.log("enter"); inner(); console.log("exit"); }outer();Expected output in the tested environment:
enterinnerexitThe outer function resumes after inner returns.
Example 2
function work() { Promise.resolve().then(() => console.log("reaction")); console.log("work done"); }work(); console.log("script done");Expected output in the tested environment:
work donescript donereactionThe reaction follows the synchronous script.
Common mistake
An asynchronous continuation does not keep an ordinary synchronous stack frame running while it waits.
Practice
Draw the conceptual execution stack at each console.log in the first example, then distinguish the later reaction in the second.
Run this practice in the documented local environment. ByteMind module and asynchronous grader support is not yet verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Synchronous calls and execution stack — Knowledge Check
Reason about the concept and predict its behavior in the indicated environment.
When does an ordinary caller resume after calling a synchronous function?
Can a fulfilled promise reaction interrupt the currently running synchronous script?
What is an execution-context stack primarily in ECMAScript?
For Synchronous calls and execution stack, what is the console output of example 1 in Node.js 22.16.0?
function inner() { console.log("inner"); }function outer() { console.log("enter"); inner(); console.log("exit"); }outer();For Synchronous calls and execution stack, what is the console output of example 2 in Node.js 22.16.0?
function work() { Promise.resolve().then(() => console.log("reaction")); console.log("work done"); }work(); console.log("script done");