ES6 вопросы и ответы для интервью
Вопрос 21. What is the 'default parameter value' feature in ES6?
Default parameter values allow you to specify default values for function parameters if no value or undefined is passed.
Example:
function greet(name = 'Guest') { console.log(`Hello, ${name}!`); }
Вопрос 22. Explain the 'Object.assign()' method in ES6.
Object.assign() is used to copy the values of all enumerable own properties from one or more source objects to a target object.
Example:
const target = {}; const source = { a: 1, b: 2 }; Object.assign(target, source);
Вопрос 23. What is the 'Array.from()' method in ES6?
Array.from() is used to create a new shallow-copied array from an array-like or iterable object.
Example:
const arrayLike = { 0: 'a', 1: 'b', length: 2 }; const newArray = Array.from(arrayLike);
Вопрос 24. Explain the 'Array.of()' method in ES6.
Array.of() is used to create a new array with a variable number of arguments, regardless of their types.
Example:
const newArray = Array.of(1, 'hello', true);
Вопрос 25. What is the purpose of the 'Array.findIndex()' method in ES6?
Array.findIndex() is used to find the index of the first element in an array that satisfies a given condition.
Example:
const numbers = [1, 2, 3, 4, 5]; const index = numbers.findIndex(num => num > 2);
Самое полезное по оценкам пользователей: