Exam JavaScript-Developer-I Topic 1 Question 115 Discussion

Actual exam question for Salesforce's JavaScript-Developer-I exam
Question #: 115
Topic #: 1
Given the code below:
01 const delay = async delay = > {
02 return new Promise((resolve, reject) = > {
03 console.log(1);
04 setTimeout(resolve, delay);
05 });
06 };
07
08 const callDelay = async () = > {
09 console.log(2);
10 const yup = await delay(1000);
11 console.log(3);
12 };
13
14 console.log(4);
15 callDelay();
16 console.log(5);
What is logged to the console?

Suggested Answer: A Vote an answer

Execution order:
* Top-level code runs synchronously:
* Line 14: console.log(4); # logs 4.
* Line 15: callDelay(); is called.
* Inside callDelay:
* Line 9: console.log(2); # logs 2.
* Line 10: await delay(1000);:
* Calls delay(1000).
* Inside delay(1000):
* Line 3: console.log(1); # logs 1.
* Line 4: setTimeout(resolve, delay); schedules resolve in 1000 ms.
* delay returns a pending Promise. await pauses callDelay here and returns control to the event loop.
* Back to top-level:
* Line 16: console.log(5); # logs 5.
So synchronous log sequence is: 4, 2, 1, 5.
* After ~1000 ms:
* The setTimeout in delay resolves the Promise.
* The await in callDelay resumes.
* Line 11: console.log(3); # logs 3.
Final log order: 4 2 1 5 3.
Both A and B show the same sequence; one must be chosen, so A is correct.
Concepts: async/await flow, Promise resolution timing, event loop, and ordering of synchronous vs timer callbacks.

by Beck at Aug 26, 2026, 12:20 AM

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Nick name: Submit Cancel
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

0
0
0
10