Hacker News new | ask | show | jobs
by s0uthPaw88 1963 days 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/Refe...

1 comments

`null` isn't a valid value for "date" because it is defined as `date?: Date` which evaluates to the type "Date or undefined"
Yes assuming you are in strict mode, but not true otherwise.
If you had something typed as `any` and the value was `null` it would be possible to encounter an issue