LearnFrenzy
Sign in Take a free test

Destructuring · Destructuring MCQ · Question 12

Why "= {}" after a parameter pattern? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

Why is function init({ debug = false } = {}) written with = {}?

  • A To make debug read-only
  • B So init() can be called with no argument without trying to destructure undefined Correct
  • C To copy the argument
  • D It is required syntax for every destructured parameter
Correct Answer: Option B

Without it, init() would destructure undefined and throw a TypeError. With it, the empty object is destructured and debug defaults to false.

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