Question 18
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const { 0: a, 2: c, length } = ["x", "y", "z"];
console.log(a, c, length);
- A x y 3
- B undefined undefined 3
- C x z 3 Correct
- D TypeError
Correct Answer: Option C
Arrays are objects whose indexes are property keys, so an object pattern can pick indexes and length directly.
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!