Skip to content

Instantly share code, notes, and snippets.

@teffcode
Last active October 20, 2020 10:24
Show Gist options
  • Select an option

  • Save teffcode/417c14415b7834cb526a1c1a0ff67976 to your computer and use it in GitHub Desktop.

Select an option

Save teffcode/417c14415b7834cb526a1c1a0ff67976 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 Always consider using rest operator as the last element, otherwise it will be thrown: SyntaxError: rest element may not have a trailing comma. We could use let [first, last, ...rest] = ["馃嵀", "馃巸", "馃懟", "馃崿"] and the result of the console.log(rest[0]) would be: 馃懟

Explanation based on 馃憠馃徏 Destructuring assignment - Assigning the rest of an array to a variable | MDN

Code:

let [first, ...rest, last] = ["馃嵀", "馃巸", "馃懟", "馃崿"]
console.log(rest[0])


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 Siempre considera usar el operador rest como 煤ltimo elemento, sino, se lanzar谩 un SyntaxError: el elemento rest no puede tener una coma al final. Podr铆amos usar let [first, last, ...rest] = ["馃嵀", "馃巸", "馃懟", "馃崿"] y para el console.log(rest[0]) obtendr铆amos como resultado: 馃懟

Explicaci贸n basada en 馃憠馃徏 La desestructuraci贸n - Asignar el resto de un arreglo a una variable | MDN

C贸digo:

let [first, ...rest, last] = ["馃嵀", "馃巸", "馃懟", "馃崿"]
console.log(rest[0])


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