What is the output of the following code: console.log([…”Hello”]);?
a)
["H", "e", "l", "l", "o"]
b)
"Hello"
c)
[["H", "e", "l", "l", "o"]]
d)
undefined
Answer:
a)
["H", "e", "l", "l", "o"]
Explanation:
The spread operator (...
) spreads the elements of an iterable (like a string) into individual elements. When applied to the string "Hello"
, it splits the string into an array of individual characters: ["H", "e", "l", "l", "o"]
.