DEV Community

Cover image for πŸš€ Ultimate Guide: JavaScript Interview Questions and Answers (2025 Edition) - Part 3
Atul Tripathi
Atul Tripathi

Posted on

πŸš€ Ultimate Guide: JavaScript Interview Questions and Answers (2025 Edition) - Part 3

πŸš€ Ultimate Guide: JavaScript Interview Questions and Answers (2025 Edition) - Part 3

In this third part of our JavaScript interview series, we will focus on theoretical concepts that are crucial for understanding JavaScript at a deeper level. These questions will help you strengthen your fundamental knowledge and impress interviewers with clear explanations. πŸ“Œ

Let’s dive in! πŸ”₯


🟒 JavaScript Theoretical Questions

1. What is the difference between JavaScript and ECMAScript?

ECMAScript (ES) is a standard that defines how JavaScript should work. JavaScript is an implementation of ECMAScript.

  • ECMAScript provides rules, guidelines, and updates (e.g., ES6, ES7).
  • JavaScript follows these specifications and adds web-specific features (DOM, BOM).

2. What is the difference between compilation and interpretation?

  • Compilation: The entire code is converted into machine code before execution (e.g., C, Java).
  • Interpretation: Code is executed line by line, as in JavaScript.
  • JavaScript is JIT (Just-in-Time) compiled, meaning it is a mix of both.

3. What is the JavaScript Execution Context?

It is an environment where JavaScript code is executed. There are three types:

  1. Global Execution Context (GEC): Created by default.
  2. Function Execution Context (FEC): Created for each function call.
  3. Eval Execution Context: Created inside eval().

4. What are Hoisting and Temporal Dead Zone (TDZ)?

  • Hoisting: JavaScript moves variable and function declarations to the top before execution.
  • TDZ (Temporal Dead Zone): The time between variable creation and initialization (for let and const).

Example:

console.log(a); // undefined (Hoisted)
var a = 10;

console.log(b); // ReferenceError (TDZ)
let b = 20;
Enter fullscreen mode Exit fullscreen mode

5. What is Scope in JavaScript?

Scope determines the visibility of variables:

  • Global Scope: Accessible anywhere in the program.
  • Local Scope: Exists within functions.
  • Block Scope: Available only within {} (for let and const).
  • Lexical Scope: Functions can access variables from their parent scope.

🟑 Advanced Theoretical Concepts

6. What is the difference between a Polyfill and a Transpiler?

  • Polyfill: A piece of code that provides modern functionality in older browsers.
  • Transpiler: Converts modern JavaScript (ES6+) into older versions using tools like Babel.

7. What are Higher-Order Functions in JavaScript?

A function that takes another function as an argument or returns a function.

Example:

function multiplier(factor) {
  return function (num) {
    return num * factor;
  };
}
const double = multiplier(2);
console.log(double(5)); // 10
Enter fullscreen mode Exit fullscreen mode

8. What is the difference between a Callback and a Promise?

  • Callback: A function passed into another function and executed later.
  • Promise: An object representing an asynchronous operation with states (Pending, Fulfilled, Rejected).

9. What are Generator Functions in JavaScript?

A special function that can be paused and resumed using yield and next().

Example:

function* generatorFunc() {
  yield 1;
  yield 2;
  yield 3;
}
const gen = generatorFunc();
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
Enter fullscreen mode Exit fullscreen mode

10. What is the difference between localStorage, sessionStorage, and cookies?

Storage Type Lifespan Size Sent with Requests?
localStorage Permanent 5MB ❌ No
sessionStorage Until tab closes 5MB ❌ No
Cookies Defined by expiry 4KB βœ… Yes

πŸ”΄ Miscellaneous Theoretical Questions

11. What is the difference between Event Bubbling and Event Capturing?

  • Event Bubbling: Events start at the target element and bubble up to the parent elements.
  • Event Capturing (Trickling): Events start at the root and go down to the target.

Example:

document.querySelector("button").addEventListener("click", () => {
  console.log("Button clicked");
}, true); // Capturing mode
Enter fullscreen mode Exit fullscreen mode

12. What is the difference between a WeakMap and a Map?

Feature Map WeakMap
Keys Any value Only objects
Garbage Collection ❌ No βœ… Yes (keys are weakly held)
Iteration βœ… Yes ❌ No

13. What is the difference between a shallow copy and a deep copy?

  • Shallow Copy: Copies only references to nested objects.
  • Deep Copy: Creates a completely independent clone.

Example:

let obj1 = { a: 1, b: { c: 2 } };
let shallowCopy = { ...obj1 };
let deepCopy = JSON.parse(JSON.stringify(obj1));
Enter fullscreen mode Exit fullscreen mode

14. What is Defer and Async in JavaScript?

  • Async: Loads script asynchronously but executes immediately.
  • Defer: Loads script asynchronously but executes in order after HTML is parsed.

Example:

<script src="script.js" async></script>
<script src="script.js" defer></script>
Enter fullscreen mode Exit fullscreen mode

15. What is Functional Programming in JavaScript?

A paradigm where functions are first-class citizens and avoid changing state.

  • Uses pure functions.
  • Avoids side effects.
  • Uses higher-order functions.

Example:

const add = (a, b) => a + b;
console.log(add(2, 3)); // 5
Enter fullscreen mode Exit fullscreen mode

🎯 Final Thoughts

Understanding these JavaScript theoretical concepts is essential for acing interviews. Make sure to practice and apply them in real-world projects! πŸš€

πŸ’¬ Got more questions? Drop them in the comments! πŸ‘‡


Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❀️