๐ฅ 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
Post #3626
5.67K
- โค 10
- ๐ 1
- ๐ 1