🔥 Web Development Interview Questions with Sample Answers — Part 5 (Advanced Concepts)
🧩 41) What is CORS and how do you handle it?
👉 Answer: “CORS (Cross-Origin Resource Sharing) is a security feature that blocks frontend requests to different domains. I handle it by adding cors middleware in Express: app.use(cors()). For production, I configure allowed origins like cors({ origin: '
https://myapp.vercel.app' }).”
⚙️ 42) Explain React Hooks and name a few you’ve used.
👉 Answer: “Hooks let you use state and lifecycle in functional components. I use useState for state, useEffect for side effects like API calls, useContext for global state, and useReducer for complex state logic.”
🌐 43) What is REST API and its principles?
👉 Answer: “REST uses HTTP methods (GET, POST, PUT, DELETE) for CRUD. Principles: stateless (no session storage), resource-based URLs (/users/1), proper status codes (200 OK, 404 Not Found), and JSON responses.”
🔄 44) Difference between state and props in React?
👉 Answer: “State is mutable data managed inside a component (useState). Props are immutable data passed from parent to child. State changes trigger re-renders; props are read-only.”
📦 45) What is Redux and when do you use it?
👉 Answer: “Redux is a state management library for complex apps with global state. I use it when local state (useState/Context) isn’t enough—like user auth across multiple components. Store → Actions → Reducers → Updated State.”
🔐 46) How do you prevent SQL injection in MongoDB?
👉 Answer: “MongoDB uses NoSQL, so no SQL injection risk. But I prevent NoSQL injection by using Mongoose schemas with validation and never passing user input directly to queries—always sanitize first.”
🚀 47) What is code splitting in React?
👉 Answer: “Code splitting loads JS bundles lazily with React.lazy() and Suspense. Example: const LazyComponent = lazy(() => import('./Component'));. Improves initial load time by loading only needed code.”
🗄️ 48) Explain MongoDB aggregation pipeline.
👉 Answer: “Aggregation processes data in stages like $match (filter), $group (aggregate), $sort. Example: db.users.aggregate([{ $match: { age: { $gt: 18 } } }, { $group: { _id: '$city', count: { $sum: 1 } } }]) for city-wise user count.”
⚡ 49) What are React Context and Provider?
👉 Answer: “Context shares data globally without prop drilling. CreateContext → Provider wraps app → useContext consumes data. Great for themes, auth user.”
🔍 50) How do you optimize React app performance?
👉 Answer: “I use React.memo, useCallback/useMemo, lazy loading, virtual scrolling for lists, code splitting, and analyze with React DevTools Profiler.”
🎯 Bonus Tip
Practice explaining diagrams on whiteboard:
Draw frontend → API → backend → DB flow.
Visuals impress interviewers!
Double Tap ❤️ For More