0% found this document useful (0 votes)
23 views6 pages

JavaScript Interview Questions Guide

This document is a comprehensive JavaScript interview guide featuring 60 questions tailored for Junior, Mid-Level, and Senior developers. It covers fundamental concepts, advanced techniques, and best practices in JavaScript, presented in a casual Hinglish style. The guide aims to help candidates prepare effectively for technical interviews by providing clear explanations and examples.

Uploaded by

hpandeyg16
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

JavaScript Interview Questions Guide

This document is a comprehensive JavaScript interview guide featuring 60 questions tailored for Junior, Mid-Level, and Senior developers. It covers fundamental concepts, advanced techniques, and best practices in JavaScript, presented in a casual Hinglish style. The guide aims to help candidates prepare effectively for technical interviews by providing clear explanations and examples.

Uploaded by

hpandeyg16
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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) { [Link](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 [Link]() for selecting elements, [Link] for styles, [Link]
for content, aur [Link]() 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 ([Link]) 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: [Link](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 < [Link]; i++)), forEach ([Link](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. [Link]() 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 => [Link]()).catch(err
=> [Link](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 ([Link](thisArg,
arg1, arg2)); apply array of arguments ([Link](thisArg, [args])); bind fixed this
wala new function return karta hai ([Link](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 }); [Link](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 => [Link](x) ? [Link](x) : [Link](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 [Link]() 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 ([Link]({}, obj)), deep copy-
ing nested objects clone karta hai ([Link]([Link](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 = [Link](); 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., [Link](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 = [Link](’.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 ’./[Link]’;.

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 [Link] and [Link]?


[Link] sab promises resolve hone pe ya pehli failure pe reject karta hai; [Link]
pehla settled promise deta hai. Example: [Link]([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: [Link](’fetch’, e => [Link](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 [Link], and how does it differ from browser JavaScript?
[Link] 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) { [Link](’data’); } with
service(console).

12. How do you implement a custom event system?


EventEmitter class banao: class EventEmitter { constructor() { [Link] = {};
} on(event, fn) { [Link][event] = [Link][event] || []; [Link][event].push(
} emit(event, data) { if ([Link][event]) [Link][event].forEach(fn =>
fn(data)); } removeListener(event, fn) { [Link][event] = [Link][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. [Link]() ya Im-
[Link] use karo. Example: const obj = [Link]({ a: 1 }).

16. What are the differences between CommonJS and ES Modules?


CommonJS (require/[Link]) synchronous hai, [Link] 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!

Common questions

Powered by AI

Optimizing DOM manipulation involves several strategies: batching updates to minimize reflows, using DocumentFragment to make changes off the main document before appending, avoiding inline styles, and caching DOM queries to reduce the number of accesses. These approaches collectively decrease the load on the browser rendering engine and improve performance by reducing DOM thrashing, which can lead to inefficient re-rendering .

Service workers run in the background separate from the main browser thread, enabling capabilities such as offline caching, push notifications, and background data synchronization. They enhance web performance by caching assets with the Cache API to serve them from the cache before falling back to the network, thus speeding up load times. Service workers also provide an improvement in reliability by allowing applications to work offline or in uncertain network conditions .

Prototypal inheritance in JavaScript allows objects to inherit properties and methods from another object directly. It utilizes the prototype chain, where an object can point to another object as its prototype. This is achieved using Object.create() or the class syntax with extends. The main benefits over classical inheritance include greater flexibility, easier sharing of methods, and the ability to create complex objects while avoiding the need to create complex hierarchies. Prototypal inheritance is more suited to dynamic languages like JavaScript compared to static class-based inheritance .

Closures in JavaScript allow a function to retain access to its lexical scope even after that scope has finished executing. This is achieved by defining a function within another function and returning the inner function. The returned function can access variables from its outer function scope. For example, a counter function can be implemented using closures: function outer() { let x = 10; return () => x++; }. Here, the inner function retains access to the variable 'x', allowing it to increment it each time it is called .

The 'this' keyword in JavaScript refers to the context in which a function is executed. In non-strict mode, 'this' refers to the global object when not attached to any explicit context, or the object that owns the method invoking 'this'. In strict mode, 'this' can be undefined if not set by the execution context. Arrow functions differ as they capture 'this' from the surrounding scope rather than their own execution context .

The JavaScript event loop is responsible for handling asynchronous operations. It continuously checks the call stack to see if a function needs to run. It prioritizes microtasks, such as resolved promises and queueMicrotask, over macrotasks like setTimeout or I/O events. This ensures that microtasks are executed immediately after the currently executing task completes, providing a more responsive and non-blocking execution model .

Promises in JavaScript are used to manage asynchronous operations by representing the eventual result of an asynchronous operation. They can be in one of three states: pending, fulfilled, or rejected. Basic usage involves .then() for handling fulfillment and .catch() for handling errors. Advanced patterns include Promise.all, which waits for multiple promises to resolve or for the first one to reject, and Promise.race, which returns the result of the first promise to settle. These patterns allow for synchronization and orchestration of complex asynchronous workflows .

TypeScript enhances JavaScript programming by adding static typing, enabling design-time error checking, and enforcing strict type rules which can catch errors early in development. It also introduces interfaces and enums, improving code structure and maintainability. For complex applications, TypeScript enables better IDE support, refactoring capabilities, and real-time error detection, offering a robust structure suitable for large codebases, enhancing consistency, and reducing runtime errors .

Immutability in JavaScript can be enforced using Object.freeze() to prevent changes to objects, or by using libraries like Immutable.js that provide persistent immutable data structures. It offers benefits such as predictable state management, ease of debugging, and prevention of unintended side-effects caused by direct object modifications. This is particularly useful in functional programming paradigms and when managing state in large-scale applications to ensure performance stability and reliability .

Shallow copying in JavaScript creates a copy of an object's top-level properties, using methods like Object.assign(). It does not copy nested objects, meaning changes to nested elements in the copy will affect the original. Deep copying, on the other hand, involves cloning all levels of nested objects, ensuring complete duplication and independence from the original, often done via JSON.parse(JSON.stringify()) or libraries like Lodash. Shallow copying is simpler and faster for flat objects, while deep copying is necessary for complex, nested structures .

You might also like