ES6 Questions et reponses d'entretien
Question 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}!`); }
Question 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);
Question 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);
Question 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);
Question 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);
Les plus utiles selon les utilisateurs :