Full Stack MERN Developer Interview Questions and Answers
JavaScript (Core)
Q1: What are closures in JavaScript?
A: Closures are functions that remember the variables from their outer scope even after the outer
function has closed.
Q2: What is the difference between var, let, and const?
A: `var` is function-scoped, `let` and `const` are block-scoped. `const` cannot be reassigned.
Q3: What is a Promise in JavaScript?
A: A Promise represents a value which may be available now, or in the future, or never.
Q4: Explain async/await.
A: `async` functions return a Promise. `await` pauses the function execution until the Promise is
resolved.
Q5: What is hoisting?
A: Hoisting is JavaScript's behavior of moving declarations to the top of a scope before code
execution.
React.js
Q1: What is Virtual DOM?
A: Virtual DOM is a lightweight representation of the real DOM. React updates the real DOM only
where changes occurred.
Q2: What are React Hooks?
A: Hooks let you use state and other React features in functional components. Examples:
`useState`, `useEffect`, `useRef`.
Q3: What is the difference between controlled and uncontrolled components?
A: Controlled components use React state to control form inputs. Uncontrolled components use refs.
Q4: What is Redux?
A: Redux is a state management library. It uses a single store, reducers, and actions to manage
state.
Q5: What is useEffect used for?
A: `useEffect` is used to handle side-effects in functional components, like data fetching or
subscriptions.
Node.js
Q1: What is Node.js?
A: Node.js is a runtime environment that allows JavaScript to run on the server.
Q2: What are streams in Node.js?
A: Streams are objects that let you read or write data continuously. Types: Readable, Writable,
Duplex, Transform.
Q3: Difference between synchronous and asynchronous?
A: Synchronous code executes line by line. Asynchronous code can run without blocking the main
thread.
Q4: What is middleware in Node.js/Express?
A: Middleware are functions that execute during the request-response cycle. Used for
authentication, error handling, etc.
Q5: What is the purpose of package.json?
A: It manages the project's dependencies, scripts, and metadata.
Express.js
Q1: What is Express.js?
A: Express is a web framework for Node.js used to build APIs and web applications.
Q2: How does routing work in Express?
A: You define route handlers for specific endpoints using methods like `app.get()`, `app.post()`.
Q3: What is error-handling middleware in Express?
A: A middleware with 4 parameters (`err, req, res, next`) used to handle errors.
Q4: How do you handle form data in Express?
A: Use `express.urlencoded()` or `multer` middleware.
Q5: How to use environment variables in Express?
A: Use `dotenv` package and access via `process.env.VARIABLE_NAME`.
MongoDB
Q1: What is MongoDB?
A: MongoDB is a NoSQL database that stores data in flexible, JSON-like documents.
Q2: Difference between SQL and NoSQL?
A: SQL is relational and structured. NoSQL is non-relational, schema-less, and more scalable.
Q3: What are Collections and Documents?
A: Collections are like tables; documents are like rows in MongoDB.
Q4: What is Aggregation in MongoDB?
A: Aggregation processes data records and returns computed results (like SQL GROUP BY).
Q5: How do you perform CRUD operations in MongoDB?
A: Using `insertOne()`, `find()`, `updateOne()`, and `deleteOne()`.
MERN Stack Integration
Q1: How does React communicate with Node/Express?
A: Via HTTP requests using `fetch` or `axios` to backend API endpoints.
Q2: What is CORS and how to handle it?
A: CORS is a security feature. Use the `cors` middleware in Express to allow requests from specific
origins.
Q3: What is JWT and how is it used?
A: JWT (JSON Web Token) is used for secure user authentication and authorization.
Q4: How do you deploy a MERN stack app?
A: Frontend on Vercel/Netlify; backend on Render/Heroku/AWS; database on MongoDB Atlas.
Q5: How to protect routes in MERN stack?
A: Use JWT tokens and middleware to check authentication on both frontend and backend.