← Back to challenges

ES6: Destructuring Objects VI

JavaScriptHardlanguage_fundamentalsformattingobjectsbugs

Instructions

function shirtSize({size = "big"}) {
  return size
}

shirtSize()  // error: Cannot destructure property "size" of "undefined" or "null"

The preceding code produces an error because no object was passed to the function. Fix the function to return the default size, even if nothing is passed to the function. Don't remove the {size = "big"} object in the parameter and don't change the return statement.

Example

shirtSize( ) ➞ "big"

Notes

If you get stuck the answer is in one of the yellow notes on the MDN docs page.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Counting Adverbs