Avatar ·

How to check a variable for both null and undefined in TypeScript?

Hi everyone! I'm new to TypeScript and can't figure out null and undefined checks.\n\nI have a function that receives data from the user (for example, from a form or localStorage). The data can be either null or undefined. I want to write a universal check that catches both cases.\n\nHere is my code:\n\n```typescript\nfunction processValue(value: string | null | undefined) {\n // How to correctly check that value is not null and not undefined?\n if (value !== null && value !== undefined) {\n console.log(value.toUpperCase());\n } else {\n console.log('Value is missing');\n }\n}\n```\n\nI know you can write `value !== null && value !== undefined`, but it looks cumbersome. Is there a shorter and more elegant way? I've heard about the `??` operator, but