Consider the following example:
In the example given above,
we have an array numbers
with only one element.
We attempt to destructure the array
and
store the first two elements
in firstNumber and secondNumber,
respectively.
firstNumber assigned the value 24.
Since there is no second element
in the numbers array,
secondNumber is assigned undefined.
Hence firstNumber + secondNumber
produces NaN.
We can prevent such undesired outputs
by providing default values for
the variables firstNumber and secondNumber:
In the example given above,
firstNumber gets the value 24.
Since there is no second element
in the numbers array,
secondNumber is assigned
the default value.