LearnFrenzy
Sign in Take a free test

Destructuring · Predict the Output · Question 9

Rotating three variables Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
let a = 1, b = 2, c = 3;
[a, b, c] = [c, a, b];
console.log(a, b, c);
  • A 1 2 3
  • B 2 3 1
  • C 3 1 2 Correct
  • D 3 3 3
Correct Answer: Option C

The right-hand array [3, 1, 2] is built from the old values first, then assigned in order.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links