Question 2
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const [, x, ...y] = "hello";
console.log(x, y);
- A e [ 'l', 'l', 'o' ] Correct
- B h [ 'e', 'l', 'l', 'o' ]
- C e llo
- D e [ 'llo' ]
Correct Answer: Option A
A string is iterable by character. The comma skips "h", x gets "e", and the rest is collected into an array of characters.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!