Avatar ·

Is there a null coalescing operator in JavaScript?

Hello everyone! I'm a beginner JS developer, and I have a problem with handling values that can be null or undefined.\n\nLet's say I have a function that gets user settings, and if some property is missing, I want to substitute a default value. Currently I do it like this:\n\n```javascript\nfunction getSettings(user) {\n const theme = user.theme || 'light';\n const fontSize = user.fontSize || 16;\n return { theme, fontSize };\n}\n```\n\nBut this doesn't work quite correctly. For example, if the user explicitly specified `theme: ''` (empty string) or `fontSize: 0`, the `||` operator treats them as falsy and substitutes the default value. But I need the substitution to happen only if the value is actually null or undefined.\n\nI've heard that in some