What is the output of the following code: console.log([…”Hello”]);?

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"].

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top