Paracetamol.js馃拪| #162: Explica este c贸digo JavaScript

Cristian Fernando - Jul 8 '22 - - Dev Community

Explica este c贸digo JavaScript

Dificultad: Intermedio

console.log({...[1,2,3]})
console.log({..."hola"})
Enter fullscreen mode Exit fullscreen mode

A. { [1,2,3] }, { hola:"hola" }
B. { 0:1, 1:2, 2:3 }, { 0:"h", 1:"o", 2:"l", 3:"a" }
C. { 1, 2, 3 }, { "hola" }
D. Ninguna de las anteriores

Respuesta en el primer comentario.


Respuesta:
B. { 0:1, 1:2, 2:3 }, { 0:"h", 1:"o", 2:"l", 3:"a" }

Tanto arreglos con cadenas son elementos iterables, por ello cuando aplicamos el operador spread los 铆ndices del iterable se convierten en claves y los elementos (para arreglos) y caracteres para cadenas) representan los valores respectivamente.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .