Array Destructuring: Default and Parameters Values

Let’s discuss array destructing to set default values, extract values using rest parameters, extract parameter values, and more.

Providing a default value

When we asked for an extra value to be extracted, we got undefined. Although JavaScript is powerful, it won’t magically create values for positions that don’t exist—but you can.

Remember, from the Defining Default Values for Parameters lesson, a parameter picks up a default value if the argument is undefined. We can apply this feature here to substitute a default value if the value being extracted is undefined.

Let’s change the previous code to give a default value for nickName.

Get hands-on with 1400+ tech skills courses.