Instagram | Twitter | LinkedIn
What is the output of the following code ?
Click here to see the correct answer and explanation 馃憖
| Correct Answer | Explanation |
|---|---|
| B | arguments is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. By the way, with Spread operator (...) we can copy the contents of one array (arguments) to another (array). |
Explanation based on 馃憠馃徏 The arguments object and JavaScript | Spread Operator
Recommended reading 馃憠馃徏 Map | MDN
Code:
function favoriteSongs() {
const array = [...arguments];
array.map((song, i) => {
console.log(`${i + 1}. ${song}`);
});
}
favoriteSongs("馃敶馃敟馃尪", "馃寣猸愶笍猸愶笍猸愶笍", "馃挙猸愶笍猸愶笍");
驴 Qu茅 imprime el siguiente c贸digo ?
Haz click aqu铆 para ver la respuesta correcta y su explicaci贸n 馃憖
| Respuesta correcta | Explicaci贸n |
|---|---|
| B | El objeto arguments es una variable local disponible dentro de todas las funciones (excepto en las arrow functions) y corresponde con los argumentos pasados a la funci贸n. Por otro lado, con el Spread operator (...) podemos copiar el contenido de un array (arguments) a otro (array), y con map() podemos iterar sobre los elementos de ese array. |
Explicaci贸n basada en 馃憠馃徏 Objeto arguments y JavaScript | Spread Operator
Lectura recomendada 馃憠馃徏 Map | MDN
C贸digo completo:
function favoriteSongs() {
const array = [...arguments];
array.map((song, i) => {
console.log(`${i + 1}. ${song}`);
});
}
favoriteSongs("馃敶馃敟馃尪", "馃寣猸愶笍猸愶笍猸愶笍", "馃挙猸愶笍猸愶笍");

