21 Practical Development Coding Questions for Freshers
1. How do you reverse a string in JavaScript?
js
const str = 'hello';
const reversed = str.split('').reverse().join('');
console.log(reversed); // 'olleh'
2. What is the difference between null and undefined?
js
let a;
console.log(a); // undefined
let b = null;
console.log(b); // null
3. How do you make an HTTP GET request in JavaScript?
js
fetch('https://api.example.com/data')
.then(res => res.json())
.then(data => console.log(data));
4. How do you clone an object in JavaScript?
js
const original = { a: 1 };
const copy = { ...original };
console.log(copy); // { a: 1 }
5. How do you debounce a function in JavaScript?
js
function debounce(fn, delay) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => fn.apply(this, args), delay);
};
}
6. How to conditionally apply a class in React?
js
const isActive = true;
Page 1
21 Practical Development Coding Questions for Freshers
<div className={isActive ? 'active' : 'inactive'}>Hello</div>
7. How do you use useState in React?
js
const [count, setCount] = useState(0);
<button onClick={() => setCount(count + 1)}>Increment</button>
8. How to create a RESTful route in Express?
js
app.get('/api/users', (req, res) => {
res.send('Get all users');
});
9. How to connect MongoDB using Mongoose?
js
mongoose.connect('mongodb://localhost/test')
.then(() => console.log('Connected'))
.catch(err => console.error(err));
10. How do you return JSON from an Express API?
js
app.get('/api', (req, res) => {
res.json({ message: 'Hello World' });
});
11. What is destructuring in JavaScript?
js
const user = { name: 'Komolika', age: 22 };
const { name, age } = user;
console.log(name); // Komolika
12. What are arrow functions in JavaScript?
js
const add = (a, b) => a + b;
console.log(add(2, 3)); // 5
13. How do you sort an array of numbers?
js
const nums = [3, 1, 4];
Page 2
21 Practical Development Coding Questions for Freshers
nums.sort((a, b) => a - b);
console.log(nums); // [1, 3, 4]
14. How to fetch data on component mount in React?
js
useEffect(() => {
fetch('/api/data')
.then(res => res.json())
.then(setData);
}, []);
15. How to render a list in React?
js
const items = ['A', 'B'];
{items.map(item => <li key={item}>{item}</li>)}
16. How to create a responsive layout using Flexbox?
css
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
17. How to push code to GitHub?
sh
git add .
git commit -m "Initial commit"
git push origin main
18. How to use environment variables in Node.js?
js
require('dotenv').config();
console.log(process.env.DB_URI);
19. How to validate forms in HTML?
html
<input type="email" required />
Page 3
21 Practical Development Coding Questions for Freshers
20. How to use map() in JavaScript?
js
[1, 2, 3].map(n => n * 2); // [2, 4, 6]
21. What is the difference between map() and forEach()?
js
// map returns a new array
const doubled = [1, 2].map(x => x * 2);
// forEach doesn't return
[1, 2].forEach(x => console.log(x));
Page 4