completefrontend

How to prepare for a JavaScript interview

Relearn the few ideas JavaScript questions are built on, practice predicting what code logs, write the classic utilities against tests, and rehearse your answers out loud. Here's how, with a three-week plan.

Three steps joined by arrows: explain a concept, like what a closure is; predict the output, like 1, 4, 3, 2; and write the code, like debounce

A chess player getting ready for a tournament doesn't read every chess book ever written. They study the openings that keep coming up, play timed games, and go over every game they lost to see exactly where it went wrong. Getting ready for a JavaScript interview works the same way.

To prepare for a JavaScript interview, relearn the handful of ideas JavaScript questions are built on (types, scope, closures, this, prototypes, the event loop, and promises), practice predicting what code logs, write the classic utilities like debounce and Promise.all until they're easy, and rehearse explaining all of it out loud. The rest of this post turns that into a three-week plan.

What does a JavaScript interview test?

A JavaScript round tests the language itself, not a framework. The questions come in three kinds:

  • Explain a concept. "What is a closure?" or "What's the difference between == and ===?" You answer in words, with a small example.
  • Predict the output. You get a short snippet and say every line it logs, in order.
  • Write the code. You write a function like debounce or Promise.all, and talk through its edge cases while you do.

The JavaScript interview questions are sorted into these three kinds, so you can practice each one on purpose. Writing code can also be a longer, hands-on task, which is what the JavaScript coding challenges are for.

Which topics should you study first?

The questions lean on a short list of ideas. Learn each one well enough to explain it to a friend, and keep a question for each to test yourself:

Learn the ideas before you learn answers. A memorized answer sounds fine until the first follow-up, and then there's nothing behind it.

How do you get good at output questions?

Output questions check whether you can run code in your head. The trick is to stop reading the code top to bottom and start asking, for every callback, "when does this run?"

Here's the classic shape:

console.log("1");
setTimeout(() => console.log("2"), 0);
Promise.resolve().then(() => console.log("3"));
console.log("4");

It logs 1, 4, 3, 2. The two plain console.log calls run first, because they're part of the current task. The promise callback waits in the microtask queue, and the timer callback waits in the task queue. The event loop runs one task, then every waiting microtask, then the next task. So 3 comes before 2, even though the timer's delay is zero.

A four-line snippet that logs 1, then schedules a timer that logs 2, then a promise callback that logs 3, then logs 4. It prints 1 and 4 first as synchronous code, then 3 from the microtask queue, then 2 from the task queue
Name the queue each callback waits in, and the order follows.

To get fast at these:

  1. Write your answer down before you run anything. Every line, in order.
  2. Say which queue each callback goes to: the current task, a microtask, or a new task.
  3. Run it and compare. When you're wrong, find the exact line where your model broke.

Puzzles like the async1 and async2 ordering puzzle build on this shape with async functions, and others add timers inside promises. Microtasks in depth covers the rules they rely on.

Which functions should you be able to write?

These are the classic tasks for a JavaScript coding round. Each one tests one idea in a few lines:

Write each one in the editor and run its tests. The tests tell you which edge case you forgot, like keeping this in debounce, or keeping the results of Promise.all in the same order as the input. If one feels out of reach, read the lesson first: debounce and throttle, building a promise from scratch, or polyfilling call, apply, and bind.

How should you practice explaining?

Knowing an answer and saying it clearly are two different skills. For every concept, practice a short answer in this order:

  1. One or two plain sentences that are correct.
  2. A tiny example that shows it.
  3. One edge case or common mistake.

Say it out loud, not just in your head. Record yourself once and listen back: you'll hear where you trailed off. When you can do that for every topic in the table above, a mock interview puts it all under a clock, with JavaScript questions first and a hands-on task after, and a written report at the end.

What does a three-week plan look like?

Here's one way to fit it in, at about an hour a day. Stretch it if your interview is further away.

Week Learn Practice
1 Types and coercion, scope and hoisting, closures, the this keyword Easy and medium concept questions on those topics, then once, debounce, and throttle
2 Prototypes and classes, the event loop, promises, async and await Output questions on the event loop, then sleep, promisify, and Promise.all
3 The DOM and events, modules, and whatever you got wrong Polyfills, deep clone, an event emitter, one DOM widget, and a mock round

Keep a list of every question you got wrong, with one line on why. At the end of each week, redo that list before anything new.

What should you do in the interview itself?

  • Give the short answer first, then the details. If the interviewer wants more, they'll ask.
  • Think out loud on output questions. Saying "this callback is a microtask, so it waits for the current task" shows your reasoning even if you slip on one line.
  • Ask before you code. Should debounce keep this? Should Promise.all accept values that aren't promises? Questions like these show you know where the edge cases are.
  • Write a small version that works, then improve it. A working once that you then extend beats a perfect design you never finish.

Where should you go next?

Start with the JavaScript interview questions and filter by your weakest topic. Practice the hands-on part with the JavaScript coding challenges. If the core ideas still feel shaky, go back to the JavaScript course first, starting from scope.

Written by Shrikanth PS

Senior Software Engineer at Microsoft, working on Copilot Enterprise, with more than nine years in frontend engineering.