ES6 面试题与答案
问题 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];
这有帮助吗?
添加评论
查看评论
问题 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; } }
这有帮助吗?
添加评论
查看评论
问题 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 */ });
这有帮助吗?
添加评论
查看评论
问题 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'); }
这有帮助吗?
添加评论
查看评论
问题 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';
这有帮助吗?
添加评论
查看评论
用户评价最有帮助的内容: