ES6 Interview Questions and Answers
Ques 6. Explain the concept of spread/rest operator in ES6.
The spread operator (...) is used to spread elements of an array or object, while the rest operator is used to collect elements into an array.
Example:
const arr = [1, 2, 3]; const newArr = [...arr, 4, 5];
Ques 7. What is the purpose of the 'class' keyword in ES6?
The 'class' keyword is used to create classes in JavaScript for object-oriented programming.
Example:
class Person { constructor(name) { this.name = name; } }
Ques 8. Explain the concept of promises in ES6.
Promises are used for asynchronous programming. They represent a value that may be available now, or in the future, or never.
Example:
const fetchData = new Promise((resolve, reject) => { /* async operation */ });
Ques 9. What is the 'async/await' feature in ES6?
Async/await is a syntax sugar for working with promises. It makes asynchronous code look and behave more like synchronous code.
Example:
async function fetchData() { const result = await fetch('https://example.com'); }
Ques 10. Explain the concept of modules in ES6.
Modules allow you to split your code into multiple files. You can export and import functionality between modules.
Example:
export const PI = 3.14; import { PI } from './math';
Most helpful rated by users: