LearnFrenzy
Sign in Take a free test

Destructuring · Predict the Output · Question 15

Computed keys with a default Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 15 Back to Exercise

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

main.js
const key = "score";
const { [key]: s, [`${key}2`]: s2 = 0 } = { score: 9 };
console.log(s, s2);
  • A 9 undefined
  • B undefined 0
  • C 9 9
  • D 9 0 Correct
Correct Answer: Option D

Computed keys are evaluated to "score" and "score2". score2 does not exist, so the default 0 is used.

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