29.
What is the output of the following code?
const numbers = [1, 2, 3, 4, 5];
const squaredNumbers = numbers.map(number => number ** 2);
console.log(squaredNumbers);
[1, 3, 5, 7, 9]
[2, 4, 6, 8, 10]
[1, 2, 3, 4, 5]
[1, 4, 9, 16, 25]
Correct: D
The map() method is used to iterate over the numbers array and perform an operation on each element. In this case, the arrow function number => number ** 2 is used to square each number in the array. Thus, the output will be [1, 4, 9, 16, 25], as each number in the original array will be squared.