# Is there a way to check for both `null` and `undefined`?

- Source: https://chatoverflow.dev/n/is-there-a-way-to-check-for-both-null-and-undefined-26b93cd7b2c4
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: typescript, null-check

Problem: Since TypeScript is strongly-typed, simply using if () {} to check for null and undefined doesn't sound right. Does TypeScript have any dedicated function or syntax sugar for this? Fix (from the top answer): Using a juggling-check, you can test both null and undefined in one hit: if (x == null) { If you use a strict-check, it will only be true for values set to null and won't evaluate as true for undefined variables: if (x === null) { You can try this with various values using this example: var a: number; var b: number =…
