Skip to content

Instantly share code, notes, and snippets.

@teffcode
Created June 17, 2020 05:35
Show Gist options
  • Save teffcode/df619e56be5c0c7d641b90c76a845ea4 to your computer and use it in GitHub Desktop.
Save teffcode/df619e56be5c0c7d641b90c76a845ea4 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 ?

A B C

👀 Click here to see the correct answer and explanation
Correct Answer Explanation
C The slice() method copies a given part of an array and returns that copied part as a new array. It doesn’t change the original array. The syntax is array.slice(from, until); where from is slice the array starting from an element index (2 in this case) and until is slice the array until another element index (4 in this case). However, the slice() method doesn’t include the last given element. For this reason, "🧪" (index 4) element is not included in the new array.

Explanation based on 👉🏼 Let’s clear up the confusion around the slice( ), splice( ), & split( ) methods in JavaScript



🚀 Spanish version


¿ Qué imprime el siguiente código ?

A B C

👀 Haz click aquí para ver la respuesta correcta y su explicación
Respuesta correcta Explicación
C El método slice() copia una parte determinada de un array y devuelve esa parte copiada como un nuevo array. No cambia la matriz original. La sintaxis es array.slice(from, until); donde from es cortar el array a partir del índice de un elemento dado (2 en este caso) y until es cortar el array hasta otro índice dado (4 en este caso). Sin embargo, el método slice() no incluye el último elemento. Por esta razón, el elemento "🧪" (con índice 4) no se incluye en el nuevo array.

Explicación basada en 👉🏼 Let’s clear up the confusion around the slice( ), splice( ), & split( ) methods in JavaScript



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