JavaScript_Interview_Questions_2025
JavaScript_Interview_Questions_2025
1. What are JavaScript ES6+ features that are widely used in modern development?
Modern startups leverage ES6+ features for better code readability and performance.
- Arrow Functions: `const add = (a, b) => a + b;`
- Template Literals: `Hello, ${name}!`
- Destructuring Assignment: `const { name, age } = user;`
- Spread & Rest Operator: `const newArray = [...oldArray, newItem];`
- Async/Await: `const data = await fetchData();`
- Optional Chaining: `user?.profile?.email`
- Nullish Coalescing Operator (`??`): `const val = input ?? 'default';`
**Example:**
```js
async function fetchData() {
try {
const response = await fetch('https://api.example.com');
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}
}
fetchData();
```
**Why use async/await?**
- Avoids `.then()` nesting
- Reads like synchronous code
- Better error handling with `try/catch`