Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

JavaScript (ES2026) Module 9

Errors and debugging interview questions

Interview questions on errors and debugging: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

12 questions: 4 warm-ups and 8 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    What happens when a finally block contains a return statement?

    Answered in the lesson try, catch, finally and throw

  2. Fresher

    What is the difference between TypeError and RangeError, and when should your own code throw each?

    Answered in the lesson Built-in error types and engine messages

  3. Fresher

    What does the cause option of the Error constructor do, and why pass it when you rethrow?

    Answered in the lesson Custom errors, error cause and Error.isError

  4. Fresher

    What does the debugger statement do, and when does it pause the program?

    Answered in the lesson Debugging in DevTools and Node

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to mid

    A nightly job imports a CSV file of orders and wraps each row in try … catch, logging "skipped bad row" and moving on. After a refactor, about 30 % of the rows are skipped every night, and nobody notices for a week. What went wrong, and how would you restructure the error handling?

    What it tests
    Telling expected input errors from bugs, catching narrowly and rethrowing the rest, and making skipped work visible with counts and limits while one bad row still cannot stop the whole import.
    First step
    Look at what the catch block actually caught before changing anything. Log the name and message of a few skipped rows, or run one of them without the try: a TypeError or ReferenceError from the refactored code means the catch has been hiding a bug, not bad data.
    Follow-ups

    From the lesson try, catch, finally and throw

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  2. Mid to senior

    A function writes a report to a temporary file and deletes the file in finally. In production the logs show only "EPERM: operation not permitted, unlink" and never the original failure. Explain why the first error is missing, and change the function so that callers see what really went wrong.

    What it tests
    How a throw inside finally replaces a pending error, choosing which error a caller receives, and keeping the second failure visible, including with SuppressedError and DisposableStack where the runtime has them.
    First step
    Trace the two failures in order. Writing the report threw, that error was on its way to the caller, finally ran, and the unlink call threw its own error, which replaced the first one. So the EPERM is real but secondary; the fix starts by catching the cleanup's error inside finally.
    Follow-ups

    From the lesson try, catch, finally and throw

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Mid to senior

    You maintain a payments library that 40 services use. A teammate wants to change the TypeError it throws for an amount given as text into a RangeError, to make the library consistent. What do you weigh before agreeing, and how would you ship the change?

    What it tests
    Treating error classes and codes as part of a public API, judging who breaks when a class changes, and shipping with semantic versioning, a deprecation period and a stable code that callers can rely on.
    First step
    Treat the class as part of the API, then ask whether the change is even right. Text where a number belongs is the wrong kind of value, which is exactly what TypeError means, so the current class is correct. Next, list how callers depend on it: instanceof checks, tests that assert the class, dashboards that group errors by name.
    Follow-ups

    From the lesson Built-in error types and engine messages

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Fresher to mid

    A search box passes what users type to document.querySelector, and the code handles failures with if (error instanceof SyntaxError) showHint(). Users who type "[" get no hint, and the error tracker reports a crash. Why, and how would you fix the handler?

    What it tests
    Knowing that web APIs throw DOMException objects identified by name, that a DOMException named SyntaxError is not JavaScript's SyntaxError, and that user text should be escaped or validated before it becomes a selector.
    First step
    Log what was actually caught: the constructor's name and error.name. querySelector reports an invalid selector with a DOMException whose name is "SyntaxError", and a DOMException is not an instance of JavaScript's SyntaxError, so the check is false, the catch block rethrows or ignores it, and the tracker sees a crash.
    Follow-ups

    From the lesson Built-in error types and engine messages

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Mid to senior

    After the front end started shipping minified bundles, the error dashboard groups production failures under names such as "t" and "x" instead of SeatTakenError and PaymentDeclinedError. What happened, and how would you fix the error classes and keep it from coming back?

    What it tests
    Knowing that minifiers rename classes, why names copied from new.target or constructor.name break, and fixing it in the code and the build, with a check that runs against the shipped bundle.
    First step
    Look at how the classes set their name. If a base class does this.name = new.target.name or reads this.constructor.name, the name is whatever the class is called in the shipped file, and minifiers rename classes to single letters. Compare one class in the source and in the built bundle to confirm it.
    Follow-ups

    From the lesson Custom errors, error cause and Error.isError

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Mid to senior

    An API client library exports HttpError. In one service, error instanceof HttpError is false for errors the client clearly threw, while the same check works in other services. Give two likely causes, and make the check reliable.

    What it tests
    Knowing that instanceof compares with one particular class object, how duplicate copies of a package, dual CommonJS and ES module builds and realms create a second class, and which checks survive that.
    First step
    Count the HttpError classes in that service. List the installed copies of the client with npm ls and its package name, and check whether some code loads it with require and other code with import, which can load two builds. Every copy defines a class of its own, and instanceof matches only one.
    Follow-ups

    From the lesson Custom errors, error cause and Error.isError

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  7. Mid to senior

    About 1 in 500 checkouts in production shows a total that is a few rupees off, and nobody can reproduce it on a laptop. Walk through how you would find the bug.

    What it tests
    A method for bugs that will not reproduce: collecting evidence from production, finding what the failing cases share, turning one into a local reproduction, and testing hypotheses instead of guessing.
    First step
    Turn the 1 in 500 into data before opening a debugger. Collect the failing orders with their inputs, such as the items, coupons, prices, locale and app version, and compare them with orders that came out right. Whatever all the failing ones share and the others lack is the first hypothesis to reproduce locally.
    Follow-ups

    From the lesson Debugging in DevTools and Node

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  8. Mid to senior

    To debug a staging service in a container, a teammate starts Node.js with --inspect=0.0.0.0:9229 and publishes the port so that their laptop can attach. What is the risk, and how would you debug that service safely?

    What it tests
    Knowing that the inspector allows running any code in the process, why a public binding is dangerous, and the safe alternatives: tunnels and port forwarding, opening the inspector on demand, and keeping it out of production.
    First step
    State what the port grants: any client that connects to the inspector can run arbitrary code inside the process, with its secrets and its network access, and the inspector asks for no password. Then check who can reach it: a container port published on 0.0.0.0 is open to anything that can reach the host.
    Follow-ups

    From the lesson Debugging in DevTools and Node

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All JavaScript (ES2026) interview questions · The JavaScript (ES2026) track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.