React Notes
React Notes
js Interview Notes
1. Introduction
• React.js is a JavaScript library for building UI components.
• Developed by Facebook.
• It is Component-based, Declarative, and uses a Virtual DOM.
2. Core Concepts
Components
• Function Components (preferred) and Class Components.
• Components must return JSX.
function Hello() {
return <h1>Hello World</h1>;
}
JSX
• Syntax extension that looks like HTML inside JavaScript.
Props
• Short for Properties.
• Passed from parent to child components.
<ChildComponent name="John" />
State
• useState() hook to maintain internal state.
const [count, setCount] = useState(0);
3. Lifecycle Methods
• Mounting: constructor → render → componentDidMount
• Updating: shouldComponentUpdate → render → componentDidUpdate
• Unmounting: componentWillUnmount
(For functional components, use useEffect)
useEffect(() => {
console.log("Component mounted!");
return () => console.log("Component unmounted!");
}, []);
4. Hooks
• Introduced in React 16.8.
• Common hooks:
o useState()
o useEffect()
o useContext()
o useRef()
o useReducer()
5. State Management
• useState for local component state.
• Context API for light global state.
• Redux / Zustand for complex state management.
6. Routing
• Use React Router for navigation between components.
import { BrowserRouter, Route, Routes } from 'react-router-dom';
<BrowserRouter>
<Routes>
<Route path="/home" element={<Home />} />
</Routes>
</BrowserRouter>
7. Best Practices
• Keep components small and reusable.
• Lift the state up when needed.
• Use keys when rendering lists.
• Use Error Boundaries for catching JavaScript errors.
Node.js Interview Notes
1. Introduction
• Node.js is a JavaScript runtime built on Chrome's V8 engine.
• Enables running JavaScript outside the browser (server-side).
2. Core Concepts
Event-driven Architecture
• Non-blocking, asynchronous architecture.
Single-threaded
• Uses a single thread to handle multiple requests with event loop.
3. Modules
• Built-in: fs, http, path
• Third-party: express, mongoose, jsonwebtoken
const fs = require('fs');
const express = require('express');
5. Express.js
• Minimal and flexible Node.js web application framework.
const express = require('express');
const app = express();
app.listen(3000);
6. Middleware
• Functions that execute during the request-response cycle.
app.use((req, res, next) => {
console.log('Middleware triggered');
next();
});
7. API Development
• CRUD Operations (Create, Read, Update, Delete) with REST API.
• Postman is often used to test APIs.
8. Database Integration
• Use MongoDB with Mongoose.
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/testdb');
9. Authentication
• JWT (JSON Web Token) used for secure authentication.
const jwt = require('jsonwebtoken');
const token = jwt.sign({ id: user._id }, 'secretKey');
Good Luck!