3 ms·
The before and after code examples for #2 are not equivalent. Default parameters are only applied if no value or undefined is passed. In the case of the value b
by s0uthPaw88 6y ago
The before and after code examples for #2 are not equivalent. Default parameters are only applied if no value or undefined is passed. In the case of the value being `null`, no default parameter is assigned, but using `date: date || new Date()` would assign `new Date()` as the value.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- dvdhnt 6y ago`null` isn't a valid value for "date" because it is defined as `date?: Date` which evaluates to the type "Date or undefined"
- s0uthPaw88 6y agoYes assuming you are in strict mode, but not true otherwise.
- s0uthPaw88 6y agoIf you had something typed as `any` and the value was `null` it would be possible to encounter an issue