← Back to challenges

ES6: Destructuring Objects III

JavaScriptHardlanguage_fundamentalsobjects

Instructions

const obj =  { two : 2 }

var { one, two } = obj

console.log(one) // outputs undefined

Sometimes an object will be missing properties we are expecting. We can avoid undefined errors by using default values. Use ES6 object destructuring to add a default value of 1 to the one variable. Ignore the .toString() function (used for validation).

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Shapes With N Sides