Core JavaScript concepts for frontend and full-stack interviews. Covers closures, promises, prototypes, event loop, and ES6+ features.
8 Questions Detailed Answers
1What is the difference between var, let, and const?
Easy
View Answer
`var` is function-scoped, hoisted, can be redeclared. `let` is block-scoped, hoisted but not initialized (TDZ), can be reassigned. `const` is block-scoped, must be initialized at declaration, cannot be reassigned (but objects/arrays can be mutated).
2Explain closures with an example.
Medium
View Answer
A closure is a function that remembers variables from its outer scope even after the outer function has returned. Example: `function counter() { let count = 0; return () => ++count; } const inc = counter(); inc(); // 1, inc(); // 2` — The inner function "closes over" `count`.
3What is the event loop?
Hard
View Answer
JavaScript is single-threaded. The event loop handles async operations: (1) Call stack executes synchronous code, (2) Web APIs handle async tasks (setTimeout, fetch), (3) Callback queue holds completed callbacks, (4) Microtask queue (Promises) has higher priority, (5) Event loop moves callbacks to call stack when it's empty.
4What is the difference between == and ===?
Easy
View Answer
`==` (loose equality) performs type coercion before comparison: `"5" == 5` is true. `===` (strict equality) checks both value and type: `"5" === 5` is false. Best practice: always use `===` to avoid unexpected bugs.
5Explain Promises and async/await.
Medium
View Answer
A Promise represents a future value with 3 states: pending, fulfilled, rejected. `async/await` is syntactic sugar over Promises. `async function getData() { try { const res = await fetch(url); const data = await res.json(); return data; } catch(err) { console.error(err); } }` — Makes async code look synchronous and easier to read.
6What is prototypal inheritance?
Hard
View Answer
Every JS object has a `__proto__` linking to its prototype. When accessing a property, JS looks up the prototype chain. `class Dog extends Animal {}` — Dog.prototype.__proto__ === Animal.prototype. This is how methods are shared without copying.
7What is debouncing and throttling?
Medium
View Answer
Debouncing: delays execution until user stops triggering (e.g., search input — wait 300ms after last keystroke). Throttling: limits execution to once per interval (e.g., scroll handler — max once per 100ms). Debounce for input, throttle for scroll/resize.
8What are higher-order functions?
Easy
View Answer
Functions that take other functions as arguments OR return functions. Examples: `map`, `filter`, `reduce`, `forEach`. Custom: `const multiply = (x) => (y) => x * y; const double = multiply(2); double(5); // 10`