Question 12
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const { length, 0: first, [length - 1]: last } = "Kiran";
console.log(length, first, last);
- A 5 K undefined
- B undefined K n
- C ReferenceError
- D 5 K n Correct
Correct Answer: Option D
The string is boxed, so length and index properties can be read. Properties are processed left to right, so length is already initialised when the computed key [length - 1] is evaluated.
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!