π 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:
- Global Execution Context (GEC): Created by default.
- Function Execution Context (FEC): Created for each function call.
-
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
andconst
).
Example:
console.log(a); // undefined (Hoisted)
var a = 10;
console.log(b); // ReferenceError (TDZ)
let b = 20;
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
{}
(forlet
andconst
). - 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
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
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
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));
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>
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
π― 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! π
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.