← All topics

JavaScript Interview Questions and Answers

Vanilla JS: types, closures, this, prototypes, async code and the event loop, DOM and browser APIs.

225 questions for JavaScript interviews with answers and explanations - Junior, Middle and Senior levels. Sample questions, online quizzes and coding tasks.

Questions by level

Sample questions

A few questions from each level with the correct answer and an explanation.

JavaScript · Junior

  1. How many data types does JavaScript have according to the specification?

    Correct answer: 8: seven primitives and object

    Primitives: number, bigint, string, boolean, null, undefined, symbol. Everything else is object, including arrays, functions and dates. Functions are objects, even though typeof returns 'function' for them.

  2. What does typeof null return?

    Correct answer: 'object'

    It's a historical bug from the language's first implementation, kept for compatibility. null is a separate primitive. Check for it with strict equality: value === null.

  3. What does typeof NaN return?

    Correct answer: 'number'

    NaN (Not-a-Number) is a special value of the number type, the result of an invalid math operation such as 0 / 0 or Number('abc'). Check for it with Number.isNaN(x).

  4. How does let differ from var?

    Correct answer: let is scoped to a {} block, var to a function

    A var declared inside an if or for is visible throughout the function. Also, var is hoisted with the value undefined and becomes a window property at the top level, while let and const are in the "temporal dead zone" until declared.

All 75 questions with answers →

JavaScript · Middle

  1. How do call, apply and bind differ from each other?

    Correct answer: call/apply invoke immediately, bind returns a new function

    fn.call(ctx, a, b) and fn.apply(ctx, [a, b]) invoke immediately with the given this. fn.bind(ctx, a) returns a function with a permanently bound context and partially applied arguments. None of them affect arrow functions: they have no own this.

  2. How does the engine look up a property the object itself doesn't have?

    Correct answer: It walks up the prototype chain until it finds the property or reaches null

    Every object has a hidden [[Prototype]] link (Object.getPrototypeOf). That's how arrays get map from Array.prototype and all objects get toString from Object.prototype. Scope lookup applies to variables, not properties.

  3. What does Object.create(proto) do?

    Correct answer: Creates a new empty object whose prototype is proto

    The properties of proto aren't copied - they're accessible through the prototype chain. Object.create(null) creates an object with no prototype at all: a handy "clean" dictionary without inherited keys like toString.

  4. What are classes in JavaScript really?

    Correct answer: Syntax on top of prototypal inheritance with a few extra checks

    Class methods go into Class.prototype, and extends builds the prototype chain. But there are differences from constructor functions: a class can't be called without new, its body runs in strict mode, methods are non-enumerable, and there are private #x fields and static.

All 75 questions with answers →

JavaScript · Senior

  1. How does the event loop process tasks in the browser?

    Correct answer: One macrotask, then the whole microtask queue, then a possible render

    After each macrotask (script, event, timer), the microtask queue is drained completely, including microtasks added along the way. Then the browser may update rendering (calling requestAnimationFrame) if it's time for a frame. That's why a long chain of microtasks also blocks rendering.

  2. How do you globally track unhandled promise rejections in the browser?

    Correct answer: The unhandledrejection event on window

    window.addEventListener('unhandledrejection', e => report(e.reason)) is the standard way to send such errors to monitoring. Synchronous unhandled errors are caught by the error event on window. There's no Promise.onError method.

  3. What does for await...of do?

    Correct answer: Iterates over an async iterable, awaiting each value

    It works with objects that have Symbol.asyncIterator: async generators, streams (ReadableStream), API pagination. Iterations run sequentially. To process an array of promises in parallel, use Promise.all.

  4. What is Proxy used for?

    Correct answer: To intercept operations on an object: reads, writes, deletions

    Traps such as get, set, has and deleteProperty let you implement reactivity (that's how Vue 3 works), validation, logging and default values. Reflect provides the default behavior of operations for use inside traps.

All 75 questions with answers →

Combined quizzes with this topic

Questions from several topics at once - just like an interview for a specific role.

Coding tasks

Write your solution right in the browser, and tests check it instantly. Interview classics: debounce, throttle, deepClone, Promise.all, EventEmitter, an LRU cache and more.

Open tasks →