๐ฅ Web Development Interview Questions with Sample Answers โ Part 2
โก 11) How do you handle loading states in your app?
๐ Answer: โI use a loading state in React using useState. Before making an API call, I set loading = true. After receiving response, I set it to false. In UI, I conditionally render a loader or spinner while data is loading.โ
๐ 12) What is the difference between synchronous and asynchronous code?
๐ Answer: โSynchronous code runs line by line. Asynchronous code allows tasks like API calls to run in background without blocking execution. JavaScript uses async/await or promises to handle async operations.โ
๐ง 13) How do you prevent unnecessary re-renders in React?
๐ Answer: โI use React.memo for components, useMemo for expensive calculations, and useCallback for functions. Also, I avoid unnecessary state updates.โ
๐ก 14) How do you handle API failures?
๐ Answer: โI use try/catch for async calls. If API fails, I show error messages in UI and sometimes retry logic or fallback UI.โ
๐ 15) Where do you store JWT token on frontend?
๐ Answer: โUsually in localStorage or cookies. For better security, HttpOnly cookies are preferred to prevent XSS attacks.โ
๐๏ธ 16) How do you handle large datasets in MongoDB?
๐ Answer: โI use pagination (limit & skip), indexing for faster queries, and aggregation pipelines if needed.โ
โ๏ธ 17) What is middleware in Express and where did you use it?
๐ Answer: โMiddleware is a function that runs before request reaches route. I used it for authentication (JWT verification), logging, and parsing JSON.โ
๐ 18) How do you ensure data consistency in your app?
๐ Answer: โI validate data on both frontend and backend, use schema validation in Mongoose, and handle edge cases properly.โ
๐ 19) How do you improve performance of your backend?
๐ Answer: โI use caching, optimize database queries, add indexing, and reduce unnecessary API calls.โ
๐ 20) How do you handle environment variables in production?
๐ Answer: โI use .env files locally and environment settings in deployment platforms like Vercel/Render. Sensitive data like API keys and database URLs are stored securely.โ
Double Tap โค๏ธ For More
Post #3621
5.87K
- โค 11