Hacker News new | past | comments | ask | show | jobs | submit login

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...




`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




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: