Question 19
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const [first, , third = "def", ...rest] = [1, 2, undefined, 4, 5];
console.log(first, third, rest);
- A 1 undefined [ 4, 5 ]
- B 1 2 [ undefined, 4, 5 ]
- C 1 def [ 4, 5 ] Correct
- D 1 def [ 2, 4, 5 ]
Correct Answer: Option C
The empty comma skips 2. The third element is undefined, so the default "def" applies. rest gets everything after it.
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!