JavaScript Interview Coding Challenge
Question on event loop fundamentals like microtask, macrotask, call stack.

If you’ve ever walked into a JavaScript interview and thought, “This won’t be that bad,” just to be knocked out in the first 15 minutes…
hey, same here.
But here’s the thing nobody tells you — it’s not just about knowing JavaScript. It’s about understanding how JavaScript thinks and works.
Let me walk you through a challenge that I wish I had solved before my first senior dev interview. Because when it came up unexpectedly?
I blanked and wanted to run away😂

The Question That Caught Me Off Guard
What will be printed on console?
Promise.resolve().then(() => console.log(1));
queueMicrotask(() => console.log(2));
setTimeout(() => console.log(3), 0);
console.log(4);
new Promise(() => console.log(5));
(async () => console.log(6))();Now stop. Don’t scroll yet.
If you’re thinking: “Let me try this in the console,” — you’re doing it wrong.
You don’t need to execute. You need to reason.
Let’s Break It Down (Like an Interviewer Would)
The moment you see this kind of question, you’re not being tested for just the right output. You’re being tested on your mental model of the event loop. What is the priority given to each one of the task as almost all of them are async leaving simple console.log
Here’s what actually happens:
4
5
6
1
2
3Why?
console.log(4)is a regular sync log.new Promise()executes the body immediately, so 5 logs.- An async IIFE is just a fancy way of saying: run
console.log(6)now. Promise.resolve().then()andqueueMicrotask()are both microtasks — they run right after the current call stack clears.setTimeout()is a macrotask — it waits for microtasks to finish.
What You Should Really Learn from This
Interviewers aren’t just checking for the answer. They want to see:
- How you talk through your thinking
- How comfortable you are with async behavior
- Whether you understand micro vs macro tasks (and yes, it will come up)
- How calm do you stay when things look unfamiliar and what is your approach of thinking
Practice This Way Instead
Here’s how I started getting better:
- I’d pick a question like this every day and explain it out loud to myself (mirror coaching works, seriously) or record a video of yourself while explaining and watch it later to understand what mistakes you made.
- I’d draw the call stack and queues.
- I made cheatsheets for quirks like
new Promise()running immediately orawaitbeing sugar over.then().
The more I did this, the more I felt in control during interviews.
Final Thought
If you’re still memorizing answers — stop.
Start understanding the why behind them. Because real interviews aren’t about acing a quiz — they’re about showing you can think clearly under pressure.
What’s one JavaScript quirk that tripped you up during an interview? Drop it in the comments so we can all learn from it (and maybe cry together 😅).
At Dev Simplified, We Value Your Feedback 📊
👉 Want to write with us? Join us on our whatsapp channel
👉 Have any suggestions? Let us know in the comments!