Mastering JavaScript requires a deep understanding of its unique runtime environment, from the nuances of the Event Loop to the power of closures and prototypal inheritance.
JavaScript Interview Questions (Q&A + Deep Understanding)
SECTION 1: Core Fundamentals
1. What is JavaScript?
Answer:
JavaScript is a single-threaded, synchronous, interpreted language with asynchronous capabilities.
Key Concepts:
- Runs in browser + server (Node.js)
- Uses event loop for async behavior
- Prototype-based (not classical OOP)
2. What is the difference between `var`, `let`, and `const`?
| Feature | var | let | const |
|---|---|---|---|
| Scope | Function | Block | Block |
| Re-declare | ✅ | ❌ | ❌ |
| Reassign | ✅ | ✅ | ❌ |
| Hoisting | Yes (undefined) | Yes (TDZ) | Yes (TDZ) |
Why is `var` dangerous?
- 👉 Because it ignores block scope → causes bugs
3. What is Hoisting?
Answer:
Hoisting means:
JavaScript moves declarations to the top before execution
Example:
- 👉 Internally becomes:
What about `let` and `const`?
They are hoisted BUT:
They stay in Temporal Dead Zone (TDZ)
4. What is the Temporal Dead Zone (TDZ)?
Answer:
Time between:
- variable hoisting
- and initialization
- 👉 Accessing variable → ReferenceError
5. What is a Closure?
Answer:
A closure is:
A function that remembers variables from its outer scope
Example:
Why is closure important?
Used in:
- data privacy
- callbacks
- React hooks
- memoization
SECTION 2: Execution & Event Loop
6. What is the Event Loop?
Answer:
Event loop manages:
Execution of synchronous + asynchronous code
Execution Order:
- 1. Call Stack
2. Microtask Queue (Promises) 3. Macrotask Queue (setTimeout)
Example:
Output:
Why does Promise run before setTimeout?
- 👉 Because:
- Promises → microtask queue
- setTimeout → macrotask queue
7. What is Call Stack?
Answer:
A stack that tracks function execution.
Stack:
SECTION 3: Objects & Prototypes
8. What is Prototype?
Answer:
Every JavaScript object has:
Hidden link to another object (prototype)
Example:
Why important?
Used for:
- inheritance
- method sharing
- performance
9. Difference: `__proto__` vs `prototype`
| Feature | **proto** | prototype |
|---|---|---|
| Used by | Objects | Functions |
| Purpose | Link to parent | Define properties for instances |
10. What is Prototypal Inheritance?
SECTION 4: Functions & Advanced Concepts
11. What is `this` keyword?
Answer:
this refers to:
The object calling the function
Cases:
| Scenario | this |
|---|---|
| Global | window |
| Method | object |
| Arrow function | lexical |
Example:
12. Arrow Function vs Normal Function
| Feature | Normal | Arrow |
|---|---|---|
| this | dynamic | lexical |
| arguments | available | not |
| constructor | yes | no |
13. What is Currying?
14. What is Debouncing?
Answer:
Limits function execution after delay.
Example:
15. What is Throttling?
Limits execution to once per interval.
SECTION 5: Async JavaScript
16. What is Promise?
Answer:
Promise represents:
Future value (pending, fulfilled, rejected)
Example:
17. What is async/await?
Why use it?
- cleaner than
.then() - readable
- synchronous-like code
18. Difference: Promise vs Async/Await
| Feature | Promise | Async/Await |
|---|---|---|
| Syntax | chaining | cleaner |
| Error | .catch | try/catch |
SECTION 6: Important Edge Cases
19. What is `==` vs `===`?
| Operator | Behavior |
|---|---|
| `==` | loose equality |
| `===` | strict equality |
20. What is NaN?
- 👉 Special value meaning “Not a Number”
21. What is Event Delegation?
Answer:
Using parent to handle child events.
22. What is Deep Copy vs Shallow Copy?
Shallow:
Deep:
SECTION 7: Practical Coding Questions
23. Reverse a string
24. Check palindrome
25. Flatten array
26. Remove duplicates
FINAL INTERVIEW STRATEGY
🔑 How to Answer in Interview:
Always structure like:
🔥 Most Asked Topics:
- closures
- event loop
- promises
- this keyword
- prototypes
- async/await
Final Mental Model
JavaScript =
Execution Context + Event Loop + Prototype System
Riverpod provides high simplicity, high scalability, and high testability compared to generic Providers or heavy BLoC architectures.
Archive Directory arrow_outward