Instagram | Twitter | LinkedIn
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 pop() method removes the last element from an array and returns that element. This method changes the length of the array. In this case, removing "🎾" from the array and printing console.log (ball) the result will be the two elements that will remain in the array 👉🏼 ["⚽️", "🏀"] |
Explanation based on 👉🏼 Array.prototype.pop() | MDN
¿ 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 pop() se utiliza para eliminar el último elemento de un array y devuelve el elemento eliminado. En este caso, se elimina "🎾" del array y al imprimir console.log(ball) el resultado van a ser los dos elementos que quedaron en el array 👉🏼 ["⚽️", "🏀"] |
Explicación basada en 👉🏼 JavaScript Array pop () | GeeksforGeeks


(function () {
var ball = ["⚽", "🏀", "🥎"]; // Declaramos el array
ball.pop(); // Metodo pop extra el elemento final del array
console.log(ball); // [ '⚽', '🏀' ]
})(); // Se auto ejecuta la funcion
Referencia: https://es.javascript.info/array