Easily assign default values while destructuring objects.
Consider below code-
A typical destructuring of objects, this code assigns
y variables to the
y props of object
This is a-ok, but what if you want to specify defaults in case any of the props are not present? Such defaults help avoid unexpected errors during further processing.
Consider below code -
What’s happening here -
zvariables to props in object.
xis found in object and the value is promptly updated to variable
zis not defined and is assigned the default value
undefinedsince there is no value present in the object and no default value is specified