ES6 perguntas e respostas de entrevista
Pergunta 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}!`); }
Pergunta 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);
Pergunta 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);
Pergunta 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);
Pergunta 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);
Mais uteis segundo os usuarios: