A developer reads a printed strip from a code-reading machine with a magnifying lens over a code card, with panels labeled What does it log?, CONSOLE.LOG, Why?, and Follow-up.

JavaScript Interview Questions: What Gets Asked and Why

by Sarah Jane Ross Updated Reading time estimate 13m intermediate

JavaScript interview questions come in four kinds: concept questions about how the language works, a coding round of algorithm problems, more and more often a review of AI-written code, and a behavioral chat. The coding round usually decides the offer, and AI hasn’t changed that yet.

Each question below comes with a short answer, what it really tests, and where to practice it.

Free Bonus: JavaScript Gotchas Cheat Sheet

JavaScript Gotchas Cheat Sheet

The JavaScript gotchas that trip up AI-written and human-written code, in one printable reference.

Get the Free Cheat Sheet »

How We Picked These Questions

Scrimba’s 2026 frontend prep guide says the JavaScript questions “cluster around five topics: closures, the this keyword, the event loop, promises, and prototypes.” No survey ranks interview topics, so that shortlist sets the concept round here.

The coding round gets the most room because the evidence says it still carries the most weight. In interviewing.io’s September 2025 survey, none of the 52 respondents from FAANG companies said their company had moved away from algorithm questions. Karat’s January 2026 report surveyed 400 engineering leaders and found that 62 percent of their organizations still ban AI in technical interviews.

But coaching firms told LeadDev in May 2026 that LeetCode-style tests are “slowly shifting” toward reviewing and debugging AI-generated code, and smaller companies are moving fastest. That’s why this kind of review gets its own round below, though the algorithm problem still decides most offers.

JavaScript Interview Questions About How the Language Works

Concept questions usually come early, in a phone screen or at the start of a technical round. The interviewer wants a clear explanation in your own words, followed by an example of where the idea causes bugs. A definition recited from memory rarely gets past the first follow-up.

What Is a Closure?

A closure is a function together with the variables from the place where it was created. The function can still read and change those variables after the outer function has returned.

Interviewers often ask you to write a small one, and a counter is the usual shape:

Language: JavaScript
function makeCounter() {
  let count = 0;
  return () => ++count;
}

const next = makeCounter();
console.log(next());
console.log(next());
Language: Text
1
2

The count variable outlives makeCounter() because the arrow function it returned still refers to it. Each call to makeCounter() creates a fresh count, so two counters never share one.

This question tests whether you understand scope well enough to predict what a function can see. The RealJS reference explains the closure in more depth.

How Does this Work?

The value of this depends on how a function is called. Call it as user.greet(), and this is user. Call the same function on its own, and this is undefined in strict mode, which covers every ES module and class body. The new keyword sets this to the new object, and .call(), .apply(), and .bind() set it by hand.

Arrow functions are the exception. They have no this of their own and use the one from the code around them.

The interviewer wants to know whether you can explain why a method breaks when you pass it somewhere as a callback, such as to a timer or an event listener. The reference entry for this covers each rule.

What Is the Event Loop?

JavaScript runs your code on one thread, one task at a time. When the current task finishes, the event loop first runs every waiting microtask, such as promise callbacks. Only then does it pick up the next task, such as a timer callback or a click.

A common version of the question pairs a zero-millisecond setTimeout() with an already resolved promise and asks which callback runs first. The promise callback wins because microtasks always run before the next task.

Interviewers ask it to find out whether you know why a long loop freezes a page. While your code runs, nothing else can, so clicks, timers, and network callbacks all wait until it finishes.

What Is a Promise?

A promise is an object that stands for a result that isn’t ready yet. It starts out pending, and it settles once: fulfilled with a value or rejected with a reason, usually an error. You attach what happens next with .then() and .catch().

The async and await keywords are a way to write the same thing so it reads top to bottom. An async function always returns a promise, and await pauses only that function until the promise settles. The rest of the program keeps running.

Interviewers use this question to check whether you handle failure. A good answer mentions where a rejected promise’s error goes and that a try block around an await catches it.

How Does Prototypal Inheritance Work?

Every object has a hidden link to another object (or to null), called its prototype. When you read a property the object doesn’t have, JavaScript follows that link, and then the next one, until it finds the property or runs out of links. That series of links is the prototype chain.

The class keyword builds the same chain with friendlier syntax. A method you write in a class lives once on ClassName.prototype, and every instance finds it there, so a thousand instances don’t carry a thousand copies.

This question checks whether you know that classes are prototypes underneath. Older code builds objects that way by hand, and a property that seems to come from nowhere usually comes from somewhere up the chain.

Coding-Round Questions: The Part That Decides It

In the coding round, you get a short problem in plain words, write a working solution, and then explain what it costs in time and memory. Most problems come from a handful of patterns, and spotting the pattern from the description is half the work.

Each item below shows one pattern family as an interviewer might phrase it, with the idea behind a good answer. You can practice in RealJS’s JavaScript Coding Interview Practice path, which has one course for each family. The courses are for members, but each course’s Welcome lesson is a free preview.

Can You Find Two Items That Add Up to a Target?

Checking every pair works, but it’s slow on long input. The answer interviewers hope for keeps the items you’ve already seen in a Map, so each new item needs a single lookup instead of another scan.

This one tests whether you’ll trade a little memory for a lot of speed. Two pointers and sliding windows make the same trade from another angle: they avoid rescanning by walking the input in a single pass. You can practice all three in JavaScript Coding Interview: Hashing, Pointers, and Windows.

How Many Orders Fall Between These Two Dates?

When you need to answer many questions about the same data, interviewers expect you to prepare it once. Sorted data lets binary search find each boundary by halving the search range. A running total, called a prefix sum, answers any “sum of this range” question with one subtraction.

The question tests whether you notice the repeated work before you write the loop. JavaScript Coding Interview: Prefix Sums and Binary Search drills both.

Are These Brackets Balanced?

A stack solves the brackets problem. Each opening bracket goes on the stack, and each closing bracket must match the one on top, which comes off. The string is balanced if the stack is empty at the end.

Interviewers use it to see whether you pick the right structure when work is left unfinished. The course JavaScript Coding Interview: Stacks, Queues, and Intervals also covers queues and merging overlapping time ranges.

What’s the Maximum Depth of This Tree?

The depth of a tree is one more than the depth of its deeper subtree, and an empty tree has depth zero. That one sentence is a complete recursive solution.

The question tests recursion, including whether you get the base case right. JavaScript Coding Interview: Linked Lists and Trees has you practice tree problems both recursively and level by level, along with linked lists.

What’s the Shortest Path Through This Grid?

Treat each open cell as a node and search outward from the start, one step at a time, marking cells as you visit them. That’s breadth-first search, and the first time it reaches the goal, it has found a shortest path.

Interviewers check whether you can see a graph in a problem that never uses the word. When steps have different costs, you need a priority queue. JavaScript doesn’t have one built in, so JavaScript Coding Interview: Graphs and Heaps has you build one.

In How Many Ways Can You Climb These Stairs?

If you can take one or two steps at a time, the ways to reach a step are the ways to reach the step below it plus the ways to reach the one below that. Plain recursion solves the same smaller problems again and again, and saving each answer once makes it fast.

This is the entry point to dynamic programming, and it tests whether you spot overlapping subproblems. JavaScript Coding Interview: Backtracking and DP pairs it with backtracking, which tries choices and undoes the ones that fail.

Reviewing AI-Written Code

This round is newer and less common, but it’s growing at smaller companies. You get a function that an AI assistant wrote, and the interviewer asks, “This came from an assistant. What’s wrong with it?” You judge it as if it were a pull request.

The code usually works on the expected input and hides a bug at the edges: an empty array, a value of 0 treated as missing, a .sort() with no compare function, or a loop that stops one item early.

Interviewers want to see your method, even when you spot the bug at once. Read the code before you run it, say what “correct” means for this function, try the edge cases, and explain your fix and what it costs.

Every course in the path includes code reviews of this kind, and The JavaScript You Need to Review AI-Written Code lists the language details that trip up generated code most often.

Talking Through Your Thinking

Every coding round is also a conversation, and it often starts with “Can you walk me through your approach?” The interviewer scores how you reach the answer, so a silent, perfect solution can lose to a talked-through, slightly slower one.

A good walkthrough has four parts. Restate the problem and ask about edge cases first. Then describe a brute-force solution and its cost before improving it. Write code that someone else can read, and test it out loud on a small example before you call it done.

Those four habits match what interviewers score: communication, problem solving, code quality, and testing. Each path course ends with a mock interview scored on those same four areas.

Behavioral Questions

Most interview loops end with at least one conversation about how you work with people. There’s no code here, but a vague answer can still cost an offer that you earned in the technical rounds. Two stories you can tell well cover most of what gets asked.

Tell Me About a Bug You Shipped

Pick a real bug you shipped, and keep it to a minute or two: what happened, how you found it, what you fixed, and what you changed so it wouldn’t happen again. The interviewer is checking whether you own mistakes and learn from them, so skip any blame for whoever wrote the code first.

Tell Me About a Disagreement With a Teammate

Describe a disagreement about the work, such as an approach or a deadline, and how you settled it. Interviewers want to hear that you listened and backed your view with facts, and that the team moved forward, whoever turned out to be right.

How to Use This List

Concept questions take a few evenings to prepare for, but the coding round needs weeks of practice, so plan for it first:

  1. Take the free path quiz to see which patterns you already recognize from a problem description.
  2. Watch the free Welcome lesson of the path’s first course.
  3. Work through the path in order, one course at a time, and do each course’s mock interview before moving on.
  4. In the week before the interview, read the reference entries linked in the concept questions, and explain each one out loud in two or three sentences.

Members who take the path also get the Coding Interview Patterns and Complexity cheat sheets. Keep the behavioral answers for the last day, when two short, true stories are all you need.

Where to Start

Interviewers will ask about closures and promises, but the offer usually turns on whether you can solve a problem you haven’t seen before and explain it as you go. You build that skill by solving problems yourself.

Your next step is RealJS’s interview practice path: open its free quiz and first Welcome lesson today, and give yourself a few weeks before the first interview.

Frequently Asked Questions

These are the most common questions about preparing for a JavaScript interview, with short answers:

The same five ideas come up again and again: how functions remember variables, what this points to, the order in which the event loop runs code, how promises settle, and how objects inherit. Be ready to explain each one in two or three plain sentences, and then answer a follow-up about where it causes bugs in real code.

Yes, at most companies. Large employers report no move away from algorithm problems, and many still ban AI during the round. Some smaller companies now add a review of AI-generated code, but usually as an extra step alongside the algorithm problem.

Plan for several weeks of regular practice on the coding round, since spotting patterns takes repetition. The concept topics need far less time, often a few evenings of reading and explaining them out loud.

Frontend loops add browser topics, such as the DOM, events, and CSS layout, and sometimes a small UI task. The language concepts and the algorithm round are much the same, so the same preparation covers most of the interview.

Free Bonus: JavaScript Cheat Sheet

Get a JavaScript Cheat Sheet (PDF), a printable reference to variables, types, strings, arrays, objects, functions, classes, modules, and async basics:

RealJS JavaScript Cheat Sheet pages stacked on top of each other

About Sarah Jane Ross

Sarah Jane runs content operations at RealJS and Real Python. With over a decade in remote operations, she builds the workflows and processes that help a distributed team publish clear, reliable JavaScript and Python learning resources.

» More about Sarah Jane

Master Real-World JavaScript Skills With Unlimited Access to RealJS

Locked learning resources

Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert JavaScript developers:

Level Up Your JavaScript Skills »

Master Real-World JavaScript Skills
With Unlimited Access to RealJS

Locked learning resources

Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert JavaScript developers:

Level Up Your JavaScript Skills »

What Do You Think?

Rate this article:

Keep Learning

Related Topics: intermediate