JavaScript interview questions

Master JavaScript interview questions with 31+ curated problems, answer outlines, and placement-focused preparation.

Preview Questions

  1. Explain how JavaScript handles the call stack and task queue when both setTimeout( ) and Promise are used together. Which executes first and why?

    When JavaScript runs code, it uses a single call stack to execute tasks one by one. Any synchronous code runs first. When we use setTimeout() and Promise together, they are handled differently. The setTimeout()...

  2. What’s the difference between Object.is( ), ===, and ==? When does Object.is(NaN, NaN) behave differently?

    In JavaScript, ==, ===, and Object.is() are all used for comparison, but they behave differently in how they check equality. == (Loose Equality) : Compares values only, not types. If the types are different, JavaScript...

  3. What is the purpose of the "use strict" directive, and how does it change JS behavior?

    The "use strict" directive in JavaScript is used to enable Strict Mode, which makes the code run in a safer and more reliable way. It helps you avoid common mistakes by changing how JavaScript normally behaves. When you...

  4. What is the difference between declaring a variable using var, let, and const, and how does their behavior change inside loops?

    In JavaScript, the main difference between var, let, and const lies in how they handle scope and reassignment, especially inside loops. The var keyword is function-scoped, which means a variable declared with var can be...

  5. Is typeof null really "object"? Why does this happen historically?

    Yes, in JavaScript, the expression typeof null returns "object", but this is actually a bug in the language that has existed since the very first version of JavaScript. Historically, when JavaScript was first created,...

  6. Explain what hoisting means in JavaScript and how it behaves differently for var, let, and const.

    Hoisting in JavaScript is the process where variable and function declarations are moved to the top of their scope before the code is executed. This means you can use functions and variables even before they are...

  7. How does function hoisting differ between function declarations and function expressions?

    In JavaScript, function hoisting means that function declarations are moved to the top of their scope before the code runs. This allows you to call a function before it is actually written in the code. For example, a...

  8. Explain the difference between implicit and explicit type conversion in JavaScript.

    In JavaScript, type conversion means changing a value from one data type to another. There are two types — implicit and explicit. Implicit type conversion (also called type coercion) happens automatically when...