Speech bubbles with code brackets and a checklist on an indigo background

JavaScript interview questions test a small set of core ideas: scope, closures, promises, the event loop, and equality. Prepare a short spoken answer for each, with one example you can explain clearly.

Interviewers listen for reasoning as much as results. Say what happens, why it happens, and how you would check your answer.

Key takeaways

  • Core topics repeat: scope, closures, promises, and the event loop.
  • Answer in plain steps and explain your reasoning out loud.
  • Prefer const by default, let when a value must change.
  • Promises settle once, as fulfilled or rejected, and chains return new promises.
  • Practise with a timer and speak your answers before the interview.

How should you answer JavaScript questions?

Use a fixed pattern. Restate the question in your own words, give the short answer, then walk through a small example step by step.

When you write code, narrate your choices. Name the input, the output, and the edge cases you are handling before you start typing.

If you get stuck, say what you know and how you would test the rest. A calm partial answer shows more skill than a fast guess.

The interview questions generator can give you fresh prompts to practise this pattern aloud.

What is the difference between var, let, and const?

The var keyword is function scoped. It is hoisted, which means the declaration moves to the top of the function and starts with the value undefined.

The let and const keywords are block scoped. They stay unusable until the declaration line runs, a period called the temporal dead zone.

Use const when a binding will not be reassigned, and let when it will. Avoid var in new code, because its wider scope causes avoidable bugs.

How do closures work?

A closure is a function bundled with the variables from the scope where it was created. MDN explains that nested functions keep access to outer variables, so a closure can hold private state, in its closures guide.

A common example is a counter. The outer function creates a count variable and returns an inner function that adds one to it. Each call to the inner function updates the same count, even after the outer function has returned.

Interviewers often ask why closures matter. They power private variables, event handlers that remember context, and functions that carry settings with them.

A classic follow-up asks about loops. With var, every callback shares one binding, so callbacks can all see the final value. With let, each loop turn gets its own binding, so each callback keeps the value from its own turn.

How do promises and async code work?

A promise represents a value that is not ready yet. It starts pending and settles once, either fulfilled with a value or rejected with a reason.

Each call to the then method returns a new promise. That is why chains work: each step can return a value or another promise, and the next step receives the settled result.

Always return promises inside chain steps. If you start a promise but do not return it, later steps cannot wait for it, and errors can pass unnoticed. Attach a catch step so failures are handled in one place.

Async functions are built on promises. An async function always returns a promise, and the await keyword pauses that function until a promise settles. Say this plainly, because interviewers use it to check whether you understand the model or only the syntax.

What happens in the event loop?

JavaScript runs one task at a time. A task can be the first run of a script, a click handler, or a timer callback.

After each task, the engine runs all waiting microtasks before the next task. Promise reactions are microtasks, so they run before timer callbacks scheduled for the same moment, as MDN describes in its microtask guide.

Use that order to answer output questions. Synchronous lines run first, then promise reactions, then timer callbacks.

Practise output drills by labeling each line before you answer. Mark lines as immediate, microtask, or timer task, then read the order back. The labeling habit prevents the most common event loop errors under pressure.

How do you practise before the interview?

Practise in short timed blocks and speak every answer out loud.

  1. List the core topics: scope, closures, promises, the event loop, and equality.
  2. Write four questions for each topic and answer each in under two minutes.
  3. Solve small array and string problems with a timer running.
  4. Review weak topics on the last day instead of adding new ones.

Example: Five topics with four questions each give 20 questions. At six minutes per question, one full round takes 120 minutes, which is two hours of focused practice.

For the wider interview format, read how to handle a technical interview.

The set in technical interview questions for software engineers adds broader practice questions.

Common mistakes

The biggest mistake is memorizing answers without understanding them. One follow-up question exposes a memorized line, while a reasoned answer holds up.

Another mistake is silent coding. Interviewers cannot follow thinking they cannot hear, so narrate your plan and your checks.

Candidates also skip edge cases. Empty inputs, missing values, and duplicate items are where small problems usually fail.

The bottom line

JavaScript interviews reward clear reasoning on core topics. Master scope, closures, promises, and the event loop, and answer each question in plain steps.

Practise aloud with a timer, return your promises, and explain your edge cases. That combination shows the judgment employers are hiring for.

Frequently asked questions

What JavaScript topics come up most in interviews?

Scope, closures, promises, the event loop, equality, and array methods come up again and again. Prepare a short spoken answer for each topic, with one small example you can explain without notes. Depth on core topics beats shallow coverage of everything.

How should you answer a question you do not know?

Say what you do know, reason out loud, and state how you would check the rest. Interviewers value clear thinking and honest limits. Guessing with false confidence hurts more than a calm partial answer with a plan.

What is the difference between let and var?

The var keyword is function scoped and hoisted with an undefined value. The let and const keywords are block scoped and cannot be used before their declaration line runs. Prefer const by default and let when a value must change.

How do you explain a closure in an interview?

Say that a closure is a function bundled with the variables from the scope where it was created. The inner function keeps access to those variables after the outer function returns. Give one example, such as a counter that keeps a private count.

How much practice do you need before a JavaScript interview?

A focused week of daily practice beats one long session. Work through core topics, speak answers aloud, and solve small problems with a timer. Review your weak topics on the final day instead of learning new material.