Skip to main content

Command Palette

Search for a command to run...

Cracking JavaScript & Node.js Interviews: The Core Fundamentals You Can’t Ignore

JavaScript Interview Q&A You Must Know

Updated
4 min read
Cracking JavaScript & Node.js Interviews: The Core Fundamentals You Can’t Ignore

After giving multiple interviews for Node.js and JavaScript roles, I noticed one clear pattern →
Most companies don’t test you on fancy frameworks first.
They drill you on core JavaScript fundamentals.

At first, I assumed advanced tools and frameworks would dominate the conversation. But over and over again, the same set of JavaScript concepts kept coming up.

In this article, I’ll share the most common interview questions I faced and the kind of answers that interviewers look for.

Scope & Hoisting

Q: Explain how var, let, and const behave differently in terms of hoisting and block scope.

Answer:

  • var is function-scoped and gets hoisted with an initialization of undefined. This can lead to unexpected behavior if used before declaration.

  • let and const are block-scoped. They are hoisted too, but they remain in the Temporal Dead Zone (TDZ) until execution reaches their declaration line.

  • Key difference:

    • var → hoisted, initialized as undefined.

    • let / const → hoisted but not initialized, accessing them before declaration throws a ReferenceError.

Execution Context & Closures

Q: How does the JavaScript call stack work? What is a closure and where would you use it?

Answer:

  • The call stack is where JavaScript keeps track of function execution in a LIFO (Last In First Out) manner. Each function call creates a new execution context that gets pushed onto the stack.

  • A closure is when a function "remembers" variables from its lexical scope, even after the outer function has returned.

  • Use cases:

    • Data privacy (simulating private variables)

    • Function factories

    • Event handlers / callbacks that need access to outer scope

Asynchronous JavaScript

Q: Difference between callbacks, promises, and async/await. Why is the event loop so important?

Answer:

  • Callbacks: Functions passed as arguments, but can lead to callback hell if nested deeply.

  • Promises: Provide cleaner syntax with .then() / .catch(), avoiding callback hell.

  • Async/Await: Built on top of promises, allows writing asynchronous code in a synchronous style.

  • Event Loop:

    • Core of JS concurrency model.

    • Decides whether to execute code from the call stack or callback queue.

    • Without it, JS couldn’t handle async tasks like I/O, timers, or API calls effectively.

Array Methods

Q: When should you use map vs forEach vs filter? What’s the difference in return values?

Answer:

  • map → Transforms each element and returns a new array.

  • forEach → Executes a function on each element but returns undefined. Use it for side effects (like logging).

  • filter → Returns a new array with elements that pass a condition.

Objects & Prototypes

Q: How does prototypal inheritance work in JavaScript?

Answer:

  • Every object in JavaScript has an internal link to another object called its prototype.

  • If you access a property that doesn’t exist on the object, JS looks up the prototype chain until it finds it (or reaches null).

  • This is the backbone of inheritance in JavaScript.

Advanced Concepts

Q: What is this in different contexts? How do you handle deep cloning vs shallow cloning?

Answer:

  • this depends on how a function is called:

    • In global scope (non-strict) → window / global object.

    • Inside an object method → the object itself.

    • In arrow functions → this is lexically bound (taken from the surrounding scope).

    • With call, apply, bind → explicitly set.

  • Shallow Clone: Copies only one level (e.g., using Object.assign() or spread operator). Nested objects still reference the original.

  • Deep Clone: Recursively copies all levels. Methods include structuredClone(), JSON.parse(JSON.stringify(obj)) (with limitations), or libraries like Lodash’s cloneDeep.

Final Thoughts

The truth is → mastering these fundamentals is what gets you through technical rounds.

📌 My advice if you’re preparing:

  • Revisit core JavaScript (not just frameworks).

  • Practice small coding examples daily.

  • Focus on explaining how and why, not just the answer.

👉 If you found this helpful, share it with someone preparing for JavaScript interviews.
👉 And let me know in the comments which of these topics do you want me to cover first in detail?