You probably confused by the difference between null and undefined, For example:

const { dogName = 'snickers' } = { dogName: undefined }
console.log(dogName) // what will it be? 'snickers'!

const { dogName = 'snickers' } = { dogName: null }
console.log(dogName) // what will it be? null!

const { dogName = 'snickers' } = { dogName: false }
console.log(dogName) // what will it be? false!

const { dogName = 'snickers' } = { dogName: 0 }
console.log(dogName) // what will it be? 0!

const { dogName = 'snickers' } = { }
console.log(dogName) // what will it be? 'snickers'!

Taken from: http://wesbos.com/destructuring-default-values/

Answer from Shai Katz on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Destructuring
Destructuring - JavaScript - MDN Web Docs - Mozilla
... Objects passed into function ... have the same name or a different name than the original property, and to assign default values for the case when the original object does not define the property....
🌐
Go Make Things
gomakethings.com › how-to-set-default-values-when-destructuring-with-javascript
How to set default values when destructuring with JavaScript | Go Make Things
January 6, 2020 - But if there’s no matching item in the array or object, you want to fallback to a default value. When defining the variable names, use the equal sign (=) and the desired default value to assign a default.
🌐
DEV Community
dev.to › varundey › destructuring-javascript-objects-with-default-value-2765
Destructuring JavaScript objects with default value - DEV Community
December 30, 2019 - What if we could make use of default ... = obj; console.log(a, b, c); // 1 2 baz · Easy right? You just need to assign the values as and when you unpack it....
🌐
Wes Bos
wesbos.com › destructuring-default-values
Setting Default Values with JavaScript’s Destructuring - Wes Bos
November 15, 2016 - With destructuring we can set defaults, or fallback values so that if an item is not in the object (or Array, Map, or Set) it will fall back to what you have set at the default. ... const settings = { speed: 150 } const { speed = 750, width ...
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-set-default-values-when-destructuring-an-object-in-javascript
How to set default values when destructuring an object in JavaScript?
For example, we have added the property3 variable in the destructuring object, but if the object doesn't contain the property3, destructuring sets the undefined value to the property3 variable.
🌐
Medium
medium.com › @ayoub-mabrouk › understanding-the-javascript-destructuring-assignment-798d7c959132
Understanding the JavaScript destructuring assignment | by Ayoub Mabrouk | Medium
August 8, 2022 - As we can see undefined triggers default values. To avoid hard-coding the key name, we can handle dynamic name property with object destructuring, we may not even know the property key names in advance, or let’s say the key names are fetched from an api.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-set-default-values-when-destructuring-an-object-in-javascript
How to set default values when destructuring an object in JavaScript ? - GeeksforGeeks
January 12, 2023 - Example 1: In order to give default values in arrays when applying the destructuring concept in arrays, we need to initialize values with some value. In this way, the default values will be assigned to the variables.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Destructuring_assignment
Destructuring - JavaScript | MDN
You can only use assignment patterns as the left-hand side of the assignment operator. You cannot use them with compound assignment operators such as += or *=. Each destructured property can have a default value. The default value is used when the property is not present, or has value undefined.
Find elsewhere
🌐
Codementor
codementor.io › community › destructuring with default values in javascript
Destructuring with default values in JavaScript | Codementor
March 26, 2024 - // We get an error like TypeError: ... value. const {exportData = [], downloadData = []} = templateData || {}; /* we can then loop through the `exportData` array * using .map() or any of the es6 functions to iterate over an array. * without crashing the app */ Now, to the main part. Providing default values in destructuring assignment works only if there is no variable or its value is set to undefined...
🌐
Designcise
designcise.com › web › tutorial › how-to-set-defaults-when-destructuring-array-or-object-in-javascript
Setting Defaults When Destructuring a JavaScript Array/Object - Designcise
August 10, 2020 - Setting a default value when using the destructuring assignment syntax can be done simply by assigning a value, using the equals sign (=), to the variables we're unpacking (whether from an object or an array).
🌐
Thomas Step
thomasstep.com › blog › destructuring-objects-in-javascript
Destructuring Objects in Javascript - Thomas Step
August 12, 2021 - Let’s say you have an object that is conditionally populated with properties; attempting to destructure those properties could be a hit or a miss. The example above shows what happens if we do not provide a default value (variable is undefined), how to provide a default value (other = 'defaultOtherString'), and how to provide a default value to a renamed property (numberValue: randomNumber = 3).
🌐
Coffee bytes
coffeebytes.dev › home › english › javascript › destructuring with default values in javascript
Destructuring with default values in Javascript | Coffee bytes
March 21, 2026 - Well, to avoid this we can assign a default value when the destructuring does not find the property that we want to destructure. If you are following this example remember to clean the javascript terminal and re-declare the main object or you ...
🌐
Webdevtutor
webdevtutor.net › blog › javascript-destructuring-default-value
Exploring JavaScript Destructuring Default Values
This can help prevent errors and provide fallback values when working with potentially missing properties. To assign default values during destructuring, you can simply specify the default value using the assignment operator (=) within the destructuring syntax.
🌐
Zaiste
zaiste.net › posts › javascript-destructuring-assignment-default-values
JavaScript · Destructuring Assignment with Default Values · Zaiste Programming
August 3, 2018 - Any other value, including null, false and 0, bypasses the default values in the destructuring statement. const dummy = { name: undefined } const { name = 'Basia' } = dummy; console.log(name) ... You can combine default values with renaming in the destructuring assignment.
🌐
Learnwithparam
learnwithparam.com › blog › default-values-while-destructuring-in-javascript
Default values while Destructuring in JavaScript | Learn with Param
August 18, 2019 - Here in this example, even though lastName is not defined in object, it takes the default value we assigned while destructuring. This will be very useful when you want to have default values set in your application even if there is no value in the object.
🌐
Fridoverweij
library.fridoverweij.com › docs › jstutorial › object_destructuring.html
JavaScript Tutorial – Object destructuring
April 29, 2024 - Each destructured element or property can be appointed a default value. The default value gets assigned only when the element or property is not present or when it has value undefined.
🌐
CodeSweetly
codesweetly.com › destructuring-object
Object Destructuring – How Does Destructuring Work in JS? | CodeSweetly
JavaScript allows you to use the rest operator within a destructuring object to assign the rest of an object literal to a variable. ... Always use the rest operator as the last item of your destructuring object to avoid getting a SyntaxError.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript object destructuring
JavaScript Object Destructuring
December 17, 2023 - let person = { firstName: 'John', lastName: 'Doe', currentAge: 28 }; let { firstName, lastName, middleName = '', currentAge: age = 18 } = person; console.log(middleName); // '' console.log(age); // 28Code language: JavaScript (javascript) In this example, we assign an empty string to the middleName variable when the person object doesn’t have the middleName property. Also, we assign the currentAge property to the age variable with the default value of 18.