Skip to content

Instantly share code, notes, and snippets.

@teffcode
Last active September 22, 2020 18:04
Show Gist options
  • Select an option

  • Save teffcode/37ae061bbc61a44a5f6751f472a26d5a to your computer and use it in GitHub Desktop.

Select an option

Save teffcode/37ae061bbc61a44a5f6751f472a26d5a to your computer and use it in GitHub Desktop.

馃憢馃徏 Welcome 馃憢馃徏

Quiz banner

Instagram | Twitter | LinkedIn


Choose your language 馃憛



English version 馃殌


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("馃敶馃敟馃尪", "馃寣猸愶笍猸愶笍猸愶笍", "馃挙猸愶笍猸愶笍");


Spanish version 馃殌


驴 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("馃敶馃敟馃尪", "馃寣猸愶笍猸愶笍猸愶笍", "馃挙猸愶笍猸愶笍");


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment