JavaScript Interview Questions by @fullstackbhabhi
June 2, 2025
Arre bhai, welcome to the ultimate JavaScript interview guide from your very own @fullstackb-
habhi! Yeh document hai ekdum solid, packed with 60 questions for Junior, Mid-Level, aur
Senior developers, so you can prep like a pro and crack those tech interviews. Whether you’re
just starting or ek experienced coder, we’ve got you covered with clear, mast answers in our
signature Hinglish vibe. Taiyaar ho? Chalo, let’s dive in and make your JavaScript game strong!
1 Junior Level Questions
Yeh questions hai for those who are naye in the coding duniya, focusing on JavaScript ke basic
concepts.
1. What are the different data types in JavaScript?
JavaScript ke paas hai primitive types (Number, String, Boolean, BigInt, Symbol, Null,
Undefined) aur reference types (Object, Array, Function, Date, RegExp). Primitives nahi
badalte, but reference types ko modify kar sakte ho.
2. What is the difference between let, const, and var?
var is function-scoped, hoisted with undefined; let aur const are block-scoped, stuck in
temporal dead zone (TDZ) until defined. const ko reassign nahi kar sakte, but objects/arrays
ke andar changes ho sakte hain.
3. What is hoisting in JavaScript?
Hoisting declarations ko scope ke top pe le jata hai compilation ke time. var wale variables
undefined ban jate hain, but let/const TDZ mein rehte hain.
4. How do you declare and initialize variables in JavaScript?
Use var, let, ya const, jaise let x = 10; const y = { a: 1 };. Declaration bas naam
reserve karta hai, initialization usme value dalta hai.
5. What is the difference between == and ===?
== type coercion karke values compare karta hai (e.g., "5" == 5 is true), but === value aur
type dono check karta hai (e.g., "5" === 5 is false).
6. What is scope in JavaScript, and how does it work?
Scope batata hai variable kahan accessible hai. Global (bahar), function (function ke andar),
aur block ({} ke andar for let/const) scopes hote hain. Scope chain se variables resolve
hote hain.
7. What are arrays, and how do you manipulate them?
Arrays hote hain ordered lists (e.g., [1, 2, 3]). Manipulate karo with push() (add), pop()
(remove), map() (transform), filter() (subset), ya slice() (copy portion).
1
8. How do you handle errors in JavaScript?
Synchronous errors ke liye try-catch use karo (try { riskyCode(); } catch (e) { console.error(e.m
}). Promises ke liye .catch(). finally hamesha chalta hai.
9. What is the purpose of the this keyword?
this function ke execution context ko point karta hai. Non-strict mode mein global object
(window in browsers), method calls mein object, aur strict mode mein undefined ho sakta
hai.
10. What is the event loop, and how does it handle asynchronous tasks?
Event loop call stack, task queue (setTimeout), aur microtask queue (promises) ko manage
karta hai. Microtasks pehle chalta hai for non-blocking execution.
11. What are functions, and how do you define them?
Functions hote hain reusable code blocks. Define karo with declarations (function name()
{}), expressions (const fn = function() {}), ya arrow functions (() => {}).
12. How do you manipulate the DOM in JavaScript?
Use document.querySelector() for selecting elements, element.style for styles, element.innerHTML
for content, aur element.addEventListener() for events.
13. What is the difference between null and undefined?
null explicitly "no value" set karta hai, jabki undefined ka matlab variable declared hai
but value nahi di, ya missing argument/property.
14. How do you create and use objects in JavaScript?
Objects banao with literals ({ key: value }), constructors (new Object()), ya classes
(class MyClass {}). Access karo with dot (obj.key) ya bracket (obj[’key’]) notation.
15. What are arrow functions, and how do they differ from regular functions?
Arrow functions (() => {}) concise hote hain, surrounding scope se this lete hain, aur
constructors nahi ban sakte, na hi call/apply se this change hota hai.
16. What is strict mode, and why is it used?
Strict mode ("use strict") strict rules lagata hai, jaise undeclared variables ban hote hain,
improving code safety aur debugging.
17. What are higher-order functions in JavaScript?
Higher-order functions functions ko argument ya return ke roop mein lete hain (e.g., map,
filter, reduce). Example: array.map(x => x * 2) array ke values ko double karta hai.
18. What is the typeof operator, and how is it used?
typeof value ka type string mein deta hai (e.g., typeof 42 returns "number", typeof null
returns "object"). Type checking ke liye useful.
19. How do you iterate over arrays in JavaScript?
Arrays iterate karo with for (for (let i = 0; i < arr.length; i++)), forEach (arr.forEach(item
=> {})), for...of (for (let item of arr)), ya map jaise methods.
20. What are template literals, and how do they improve string handling?
Template literals (‘string $expression‘) expressions aur multiline strings allow karte
hain, concatenation se better readability dete hain (e.g., "Hello, " + name).
2
2 Mid-Level Questions
Yeh questions hain developers ke liye with 2-5 years experience, focusing on advanced concepts
aur practical skills.
1. What is a closure, and how is it used?
Closure ek function hai jo outer scope ke variables ko access karta hai after outer function
ends. Example: function outer() { let x = 10; return () => x++; } ek counter ba-
nata hai.
2. Explain prototypal inheritance in JavaScript.
Objects prototype chain se properties inherit karte hain. Object.create() ya class syntax
(class Child extends Parent {}) use karo, parent properties __proto__ se access hote
hain.
3. What are Promises, and how do you use them?
Promises async operations represent karte hain (pending, fulfilled, rejected). .then() success
ke liye, .catch() errors ke liye, e.g., fetch(url).then(res => res.json()).catch(err
=> console.error(err)).
4. How does the event loop prioritize tasks and microtasks?
Event loop call stack, microtasks (promises, queueMicrotask), aur tasks (setTimeout, I/O)
process karta hai. Microtasks pehle chalta hai for faster async resolution.
5. What is async/await, and why is it preferred?
async functions promises return karte hain; await promise resolve hone tak wait karta hai.
Readable, synchronous-like async code ke liye preferred, e.g., async function fetchData()
{ const res = await fetch(url); }.
6. What are call, apply, and bind, and how do they differ?
call function ko specified this aur arguments ke saath call karta hai (fn.call(thisArg,
arg1, arg2)); apply array of arguments (fn.apply(thisArg, [args])); bind fixed this
wala new function return karta hai (fn.bind(thisArg)).
7. How do you implement debouncing in JavaScript?
Debouncing function calls ko delay karta hai jab tak events pause na ho. Example: function
debounce(fn, ms) { let timeout; return (...args) => { clearTimeout(timeout); timeout
= setTimeout(() => fn(...args), ms); }; }.
8. What are key ES6+ features, and how do they enhance JavaScript?
let/const, arrow functions, destructuring, spread/rest operators, modules, aur async/await
improve scoping, conciseness, modularity, aur async programming.
9. What is event delegation, and why is it useful?
Event delegation ek parent pe listener lagata hai jo children ke events handle karta hai via
bubbling. Dynamic elements aur memory efficiency ke liye useful.
10. How do you handle CORS in JavaScript applications?
CORS server-side headers (Access-Control-Allow-Origin) se manage hota hai. Client-
side, fetch ke saath proper headers ya proxies use karo for safe cross-origin requests.
11. What are Map and Set, and when to use them?
Map key-value pairs store karta hai with any key type; Set unique values. Map flexible keys
3
ke liye, Set deduplication ke liye, e.g., new Set([1, 1, 2]) gives [1, 2].
12. How do you create custom events in JavaScript?
CustomEvent aur dispatchEvent use karo, e.g., const event = new CustomEvent(’myEvent’,
{ detail: data }); element.dispatchEvent(event);, with addEventListener for lis-
teners.
13. What is memoization, and how does it optimize performance?
Memoization function results cache karta hai for same inputs, redundant computations
kam karta hai. Example: function memoize(fn) { const cache = new Map(); return
x => cache.has(x) ? cache.get(x) : cache.set(x, fn(x)).get(x); }.
14. What are Web APIs, and how do they integrate with JavaScript?
Web APIs (DOM, Fetch, Web Storage) browser functionality dete hain. JavaScript fetch()
for HTTP requests ya localStorage.setItem() for data persistence ke saath interact karta
hai.
15. How do you manage state in JavaScript applications?
Redux for centralized state, React ke useState/useReducer for components, ya Context
API for shared state use karo, ensuring predictable updates aur scalability.
16. What is the difference between shallow and deep copying?
Shallow copying top-level properties copy karta hai (Object.assign({}, obj)), deep copy-
ing nested objects clone karta hai (JSON.parse(JSON.stringify(obj)) ya Lodash).
17. How do you implement throttling in JavaScript?
Throttling function calls ko fixed rate pe limit karta hai. Example: function throttle(fn,
ms) { let last = 0; return (...args) => { const now = Date.now(); if (now - last
>= ms) { fn(...args); last = now; } }; }.
18. What are higher-order functions, and how are they used in practice?
Higher-order functions functions ko argument ya return ke roop mein lete hain, e.g., array.filter(x
=> x > 0). Functional programming mein mapping, filtering, ya composing ke liye use hote
hain.
19. How do you optimize DOM manipulation for performance?
Reflows kam karo by batching updates, DocumentFragment use karo, inline styles avoid karo,
aur DOM queries cache karo (e.g., const el = document.querySelector(’.class’)).
20. What are JavaScript modules, and how do they improve code organization?
Modules (import/export) code encapsulate karte hain, reusable aur maintainable scripts ba-
nate hain. Example: export const fn = () => {}; import { fn } from ’./module.js’;.
3 Senior Level Questions
Yeh questions hain experienced developers ke liye, focusing on complex scenarios aur architec-
tural decisions.
1. How does JavaScript handle asynchronous operations, and what are best prac-
tices?
JavaScript callbacks, promises, aur async/await se async operations handle karta hai. Best
4
practices: async/await for readability, try-catch for errors, aur promise anti-patterns avoid
karo.
2. What are advanced Promise patterns, like Promise.all and Promise.race?
Promise.all sab promises resolve hone pe ya pehli failure pe reject karta hai; Promise.race
pehla settled promise deta hai. Example: Promise.all([p1, p2]).then(results => {}).
3. What is currying, and how is it implemented?
Currying ek function ko single-argument functions ke sequence mein badalta hai. Ex-
ample: const curry = fn => a => b => fn(a, b); const add = curry((a, b) => a
+ b); add(2)(3); // 5.
4. How do you optimize JavaScript performance in large applications?
DOM operations kam karo, lazy loading use karo, expensive functions memoize karo, memory
leaks minimize karo, aur Chrome DevTools Performance tab se profile karo.
5. What are the differences between Webpack, Parcel, and Rollup?
Webpack complex apps ke liye configurable hai; Parcel zero-config for quick setups; Rollup
libraries ke liye tree-shaking ke saath optimized. Project ke scale ke hisaab se choose karo.
6. How do you design state management for single-page applications?
Redux for centralized state, Zustand for lightweight solutions, ya React Query for server-
state use karo. Immutability, predictable updates, aur separation of concerns ensure karo.
7. What are service workers, and how do they enhance web apps?
Service workers background tasks jaise caching (Cache API), push notifications, aur offline
support ke liye scripts hain. Example: self.addEventListener(’fetch’, e => e.respondWith(caches.m
8. How do you secure JavaScript applications against common vulnerabilities?
XSS ke liye input sanitization (e.g., DOMPurify), CSRF ke liye tokens, aur HTTPS se secure
APIs use karo. User inputs validate karo aur eval() ya unsafe DOM methods avoid karo.
9. How do you ensure cross-browser compatibility in JavaScript?
Feature detection (if (’feature’ in window)), polyfills (e.g., core-js), aur Babel use
karo. Chrome, Firefox, Safari pe BrowserStack jaise tools se test karo.
10. What is Node.js, and how does it differ from browser JavaScript?
Node.js server-side JavaScript chalta hai with V8, DOM nahi hota but file I/O, modules,
aur networking support karta hai. Browser JavaScript DOM manipulation aur Web APIs
pe focus karta hai.
11. What is dependency injection, and how is it implemented in JavaScript?
Dependency injection dependencies ko functions/objects mein pass karta hai, testability im-
prove karta hai. Example: function service(logger) { logger.log(’data’); } with
service(console).
12. How do you implement a custom event system?
EventEmitter class banao: class EventEmitter { constructor() { this.events = {};
} on(event, fn) { this.events[event] = this.events[event] || []; this.events[event].push(
} emit(event, data) { if (this.events[event]) this.events[event].forEach(fn =>
fn(data)); } removeListener(event, fn) { this.events[event] = this.events[event]?.filter(
=> f !== fn); } }.
5
13. What are best practices for writing scalable JavaScript code?
Modular design (ES Modules), SOLID principles, unit tests (Jest), linting (ESLint), aur
JSDoc documentation use karo for maintainability.
14. How do you detect and fix memory leaks in JavaScript?
Chrome DevTools Memory tab se leaks detect karo. Fix karo by unused event listeners
remove karke, timers clear karke (clearInterval), aur global variables avoid karke.
15. What is immutability, and why is it important in JavaScript?
Immutability data changes rokta hai, predictable state deta hai. Object.freeze() ya Im-
mutable.js use karo. Example: const obj = Object.freeze({ a: 1 }).
16. What are the differences between CommonJS and ES Modules?
CommonJS (require/module.exports) synchronous hai, Node.js mein used; ES Modules
(import/export) async loading aur tree-shaking support karte hain, modern apps ke liye
ideal.
17. How do you optimize search functionality in JavaScript?
Efficient algorithms (e.g., binary search for sorted data), Map ya databases se indexing, aur
debounce inputs use karo to reduce unnecessary computations.
18. How does TypeScript enhance JavaScript development?
TypeScript static typing, interfaces, aur enums add karta hai, compile-time errors catch
karta hai, aur IDE support, scalability, maintainability improve karta hai.
19. What are higher-order functions, and how do they enable functional program-
ming?
Higher-order functions functions ko argument ya return ke roop mein lete hain, e.g., const
compose = (f, g) => x => f(g(x)). map, reduce, aur custom pipelines ke liye declarative
code banate hain.
20. How do you design a scalable JavaScript web application architecture?
Microservices, serverless functions, ya monoliths with separation of concerns use karo. Caching
(Redis), load balancing, aur modular frontend (React/Vue) se scalability ensure karo.
4 Credits
Big shoutout to @fullstackbhabhi for inspiring yeh mast JavaScript guide! Unke X aur Instagram
pe Hinglish tech content, with humor aur real-world examples, ne is document ko banane ka
idea diya. Follow @fullstackbhabhi for more coding tips aur tricks!