✅ MERN Stack (50 Questions with Answers)
... (previous content retained) ...
✅ JavaScript Practical Questions
1. Capitalize First Letter of Each Word
const str = "mock interview";
const result = [Link](/\b\w/g, char => [Link]());
[Link](result); // Mock Interview
1. Compare Two Arrays for Equality
const arr1 = [1,2,3];
const arr2 = [1,2,3];
const isEqual = [Link](arr1) === [Link](arr2);
[Link](isEqual); // true
1. Deep Clone an Object
const obj = { a: 1, b: { c: 2 } };
const clone = [Link]([Link](obj));
1. Flatten a Nested Array
const nested = [1, [2, [3, 4]]];
const flat = [Link](Infinity);
[Link](flat); // [1,2,3,4]
1. Find Unique Elements in an Array
const arr = [1,2,2,3,4,4];
const unique = [...new Set(arr)];
1. Throttle Function
function throttle(fn, limit) {
let inThrottle;
return function() {
if (!inThrottle) {
[Link](this, arguments);
1
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
}
}
1. Debounce Function
function debounce(fn, delay) {
let timer;
return function() {
clearTimeout(timer);
timer = setTimeout(() => [Link](this, arguments), delay);
};
}
1. Find Duplicates in Array
const arr = [1,2,2,3,4,4];
const duplicates = [Link]((item, index) => [Link](item) !== index);
1. Reverse a String
const str = "hello";
const reversed = [Link]('').reverse().join('');
1. Check Palindrome
function isPalindrome(str) {
const cleaned = [Link]().replace(/[^a-z0-9]/g, '');
return cleaned === [Link]('').reverse().join('');
}
✅ [Link] Practical Examples
1. Form Handling with useState
const [formData, setFormData] = useState({ name: '', email: '' });
function handleChange(e) {
2
setFormData({ ...formData, [[Link]]: [Link] });
}
1. Toggle Component Visibility
const [visible, setVisible] = useState(false);
<button onClick={() => setVisible(!visible)}>Toggle</button>
{visible && <div>Hello</div>}
1. Fetching Data with useEffect
useEffect(() => {
fetch('/api/data')
.then(res => [Link]())
.then(data => setData(data));
}, []);
1. Conditional Button Disable
<button disabled={![Link]}>Submit</button>
1. Render List with map()
{[Link](item => <li key={[Link]}>{[Link]}</li>)}
1. Custom Hook for Window Width
function useWindowWidth() {
const [width, setWidth] = useState([Link]);
useEffect(() => {
const handleResize = () => setWidth([Link]);
[Link]('resize', handleResize);
return () => [Link]('resize', handleResize);
}, []);
return width;
}
1. Use Context API
const UserContext = createContext();
const App = () => (
<[Link] value={{ name: 'Manoj' }}>
<Profile />
3
</[Link]>
);
1. Component Communication via Props
function Child({ onAction }) {
return <button onClick={onAction}>Click</button>;
}
1. Default Props and PropTypes
[Link] = {
name: 'Guest'
};
[Link] = {
name: [Link]
};
1. React Router Usage
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</BrowserRouter>