0% found this document useful (0 votes)
27 views2 pages

MERN Stack Interview Questions Answers

Uploaded by

atiq4811
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)
27 views2 pages

MERN Stack Interview Questions Answers

Uploaded by

atiq4811
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

Q: What are semantic tags in HTML?

A: Semantic tags clearly describe the purpose of the element (e.g., , , , ).

Q: Difference between == and === in JavaScript?


A: == compares values with type coercion, === compares both value and type.

Q: What is event bubbling in JavaScript?


A: It's the event propagation from child to parent elements in the DOM tree.

Q: How do you center a div in CSS both vertically and horizontally?


A: Use Flexbox: display: flex; justify-content: center; align-items: center;

Q: What are promises? Explain .then() and .catch().


A: Promises handle asynchronous tasks. .then() handles success, .catch() handles errors.

Q: What are components in React?


A: Reusable building blocks that return JSX to define UI elements.

Q: Difference between functional and class components?


A: Functional are simple functions, class components use ES6 classes and lifecycle methods.

Q: What are props and state in React?


A: Props are read-only inputs to components; state is mutable data managed within the
component.

Q: What is the use of useEffect and useState hooks?


A: useState handles local state; useEffect handles side effects like API calls or subscriptions.

Q: What is JSX and how is it different from HTML?


A: JSX is a syntax extension for JavaScript that looks like HTML but allows embedding JS
expressions.

Q: How do you handle forms and form validation in React?


A: Using controlled components and libraries like Formik or custom validation logic.

Q: What is middleware in Express.js?


A: Functions that execute before the final route handler, used for logging, auth, etc.

Q: How do you handle routing in Express.js?


A: Using app.get(), app.post(), etc., to define routes and route handlers.

Q: What is the use of req.params and req.body?


A: req.params contains URL parameters; req.body contains data sent in POST/PUT requests.

Q: Difference between synchronous and asynchronous code in Node.js?


A: Sync code blocks execution; async code allows non-blocking operations via callbacks/promises.

Q: How do you set up a basic Express server?


A: Import express, create app, define routes, use app.listen(port).

Q: What is a document in MongoDB?


A: A record in a MongoDB collection, similar to a JSON object.

Q: Difference between find() and findOne()?


A: find() returns an array of documents; findOne() returns a single document.

Q: How do you perform CRUD operations in MongoDB?


A: Using insertOne(), find(), updateOne(), deleteOne(), or Mongoose methods.

Q: What is Mongoose and why do we use it?


A: An ODM for MongoDB that helps define schemas and interact with MongoDB easily.

Q: What are schemas and models in Mongoose?


A: Schemas define the structure of documents; models are compiled from schemas for data
interaction.

Q: What is CORS and how do you handle it?


A: CORS is a security feature to restrict cross-origin requests. Handled using cors middleware in
Express.

Q: How does the frontend communicate with the backend in a MERN stack app?
A: Via HTTP requests (GET, POST, etc.) using Axios or Fetch API.

Q: How do you implement authentication using JWT?


A: Sign token on login, send to client, verify token in protected routes on the server.

Q: What is the difference between PUT and PATCH?


A: PUT replaces entire resource; PATCH updates only specified fields.

Q: Describe a project you’ve built using the MERN stack.


A: E.g., A task manager app using React frontend, Express/Node backend, MongoDB database.

Q: How did you manage state in your React app?


A: Using useState, useReducer, or libraries like Redux or Context API.

Q: How did you connect your React frontend to your Express backend?
A: Using Axios or Fetch to send API requests to backend endpoints.

Q: How do you deploy a MERN app?


A: Frontend on Netlify/Vercel; Backend on Render/Heroku; MongoDB on Atlas; use CORS and env
variables.

Q: What challenges did you face while building your project and how did you solve them?
A: Debugging async issues, managing state, CORS errors—solved by logging, reading docs, and
testing incrementally.

You might also like