■ JavaScript + React Interview Notes (Q&A; + Code
Examples)
JavaScript Basics
Q: var, let aur const me kya farak hai?
var → function scoped, re-declare allowed
let → block scoped, re-declare not allowed
const → block scoped, constant value
Q: == aur === me kya difference hai?
== → sirf value compare (type conversion karta hai)
=== → value + type dono compare karta hai
Q: Hoisting kya hoti hai?
JS variables aur functions ko declaration phase me top pe le jata hai.
Example:
console.log(x); // undefined
var x = 10;
Q: Closure kya hota hai?
Function jo apne parent scope ke variables ko yaad rakhta hai.
Example:
function outer(){
let count=0;
return function inner(){ count++; return count; }
}
Q: Promise vs Callback
Callback → nested, callback hell issue
Promise → better handling using .then(), .catch()
JavaScript Intermediate
Q: Event Loop kya hota hai?
Mechanism jo JS ke async tasks ko handle karta hai → Call stack, Callback queue, Microtask queue.
Q: this keyword kaise behave karta hai?
this → function ke call context pe depend karta hai.
Normal function me global ya object.
Arrow function me parent scope se inherit hota hai.
Q: map, filter, reduce kya hote hain?
map → har element ko transform karta hai
filter → condition match elements return karta hai
reduce → array ko single value me reduce karta hai.
Q: Debouncing aur Throttling kya hote hain?
Debounce → function ko delay se trigger karna.
Throttle → function ko fixed interval pe call karna.
React Basics
Q: React kya hai?
UI library jo fast rendering aur component-based development deti hai.
Q: Virtual DOM kya hai?
React ek lightweight JS object use karta hai jo real DOM ka copy hota hai. Ye diff karke sirf changed
Q: Props aur State me kya difference hai?
Props → parent se child ko data pass karne ke liye, read-only.
State → component ka internal data jo update ho sakta hai.
Q: JSX kya hota hai?
JSX ek syntax extension hai jo JS ke andar HTML jaisa code likhne deta hai.
React Hooks
Q: Hooks kya hote hain?
Special functions jo functional components me state aur lifecycle features add karte hain.
Q: useState aur useEffect kaise kaam karte hain?
useState → state banata hai functional component me.
useEffect → side effects (API call, subscriptions) handle karta hai.
Q: useMemo aur useCallback me kya difference hai?
useMemo → expensive calculation ka result cache karta hai.
useCallback → function ko cache karta hai taaki unnecessary re-renders na ho.
Q: Context API kya hota hai?
Global state management tool jo prop drilling avoid karta hai.
React Advanced
Q: HOC (Higher Order Component) kya hote hain?
Function jo ek component ko input leta hai aur ek new component return karta hai.
Q: SSR vs CSR me difference?
SSR → HTML server pe render hota hai (faster SEO).
CSR → HTML client pe render hota hai (React default).
Q: Error Boundaries kya hote hain?
Special components jo runtime errors ko catch karte hain aur fallback UI show karte hain.
Q: React 18 ke naye features kya hain?
Concurrent rendering, automatic batching, Suspense improvements.