Nice reminder about JavaScript evolving to be more useful from Trevor I. Lasn:
// Old way (pre-2021)
if (user.name === null || user.name === undefined) {
user.name = 'Anonymous';
}
// Or using the nullish coalescing operator (??)
user.name = user.name ?? 'Anonymous';
// New way (ES2021 and later)
user.name ??= 'Anonymous';
Code language: JavaScript (javascript)
The final line there uses what is called the “The nullish coalescing assignment operator assignment operator” in case you need to impress people at parties.