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 = null;

function check(x, name) {
    if (x == null) {
        console.log(name + ' == null');
    }

    if (x === null) {
        console.log(name + ' === null');
    }

    if (typeof x === 'undefined') {
        console.log(name + ' is undefined');
    }
}

check(a, 'a');
check(b, 'b');

Output

"a == null"

"a is undefined"

"b == null"

"b === null"

Answer from Fenton on Stack Overflow
🌐
W3Schools
w3schools.com › typescript › typescript_null.php
TypeScript Null & Undefined
TypeScript has a powerful system to deal with null or undefined values.
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-2-0.html
TypeScript: Documentation - TypeScript 2.0
The type checker previously considered null and undefined assignable to anything. Effectively, null and undefined were valid values of every type and it wasn’t possible to specifically exclude them (and therefore not possible to detect erroneous use of them). strictNullChecks switches to a new strict null checking mode.
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › how-to-check-null-and-undefined-in-typescript
How to check null and undefined in TypeScript ? - GeeksforGeeks
July 23, 2025 - Example: Below is an example demonstrating the use of optional chaining and nullish coalescing operators to check for null or undefined values. We declare variables that can be either undefined, null, or assigned a value. let undefinedVar: string | undefined; let nullVar: string | null = null; let assignedVar: string | null | undefined = "Hello, World!"; ... let undefinedVar: string | undefined; let nullVar: string | null = null; let assignedVar: string | null | undefined = "Hello, World!"; const checkUndefinedVar = undefinedVar ??
🌐
TutorialsPoint
tutorialspoint.com › javascript-typescript-object-null-check
JavaScript/ Typescript object null check?
A variable is undefined until and ... variable null, we must assign it a null value. To check a variable is null or not in typescript we can use typeof or "===" operator....
🌐
GitBook
basarat.gitbook.io › typescript › recap › null-undefined
Null vs. Undefined | TypeScript Deep Dive
So to check if a variable is defined or not at a global level you normally use typeof: ... if (typeof someglobal !== 'undefined') { // someglobal is now safe to use console.log(someglobal); } Because TypeScript gives you the opportunity to document your structures separately from values instead of stuff like: ... Node style callback functions (e.g. (err,somethingElse)=>{ /* something */ }) are generally called with err set to null if there isn't an error.
🌐
Upmostly
upmostly.com › home › typescript › how to detect null and undefined
How to Detect Null and Undefined in Your TypeScript Code - Upmostly
March 28, 2023 - Another way to check for null or undefined is to use the nullish coalescing operator (??), which was introduced in TypeScript 3.7.
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-check-if-null
How to correctly check for Null in TypeScript | bobbyhadz
To check for null in TypeScript, use a comparison to check if the value is equal or is not equal to `null`.
Find elsewhere
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-3-7.html
TypeScript: Documentation - TypeScript 3.7
Note that if bar is null or undefined, our code will still hit an error accessing baz. Likewise, if baz is null or undefined, we’ll hit an error at the call site. ?. only checks for whether the value on the left of it is null or undefined - not any of the subsequent properties.
🌐
Omarileon
omarileon.me › blog › typescript-null-undefined
mari. | How to Detect Null and Undefined in Your TypeScript Code
February 27, 2024 - Another way to check for null or undefined is to use the nullish coalescing operator (??), which was introduced in TypeScript 3.7. If the left-hand side of the operation is non-null it returns that, otherwise it returns the right-hand side otherwise.
🌐
Scaler
scaler.com › topics › typescript › strictnullchecks
StrictNullChecks in TypeScript - Scaler Topics
February 8, 2023 - Because nulls are permitted, the TypeScript compiler believes that the p might be null. There are many ways to solve the above error, out of which a few good ones are : ... Use if to check for null : If the condition is null or undefined.
🌐
TypeScript
typescriptlang.org › docs › handbook › advanced-types.html
TypeScript: Documentation - Advanced Types
TypeScript has two special types, null and undefined, that have the values null and undefined respectively. We mentioned these briefly in the Basic Types section. By default, the type checker considers null and undefined assignable to anything. Effectively, null and undefined are valid values ...
🌐
W3schools
w3schools.tech › tutorial › typescript › typescript_null_vs_undefined
TypeScript - null vs. undefined - TypeScript Basic Types - W3schools
In TypeScript (and JavaScript), null is a special value that represents the intentional absence of any object value.
🌐
Rampatra
blog.rampatra.com › null-vs-undefined-in-typescript-or-javascript-how-to-check-for-both-at-once
!== null vs !== undefined in Typescript or Javascript, how to check for both at once?
Use != null only when you explicitly want to check for both null and undefined. ... If offerPrice might explicitly be null, you should use offerPrice != null to handle both cases.
🌐
TypeScript
typescriptlang.org › tsconfig › strictNullChecks.html
TypeScript: TSConfig Option: strictNullChecks
When strictNullChecks is true, null and undefined have their own distinct types and you’ll get a type error if you try to use them where a concrete value is expected. For example with this TypeScript code, users.find has no guarantee that it will actually find a user, but you can write code ...
🌐
Honlsoft
honlsoft.com › blog › 2021-07-20-typescript-tips-null-coalescing
Typescript Tips: null(and undefined) Checking | Honlsoft
Thankfully, in Typescript, there are several shorthand ways to deal with nulls. The Elvis operator is a shorthand way to check for null or undefined without requiring a separate if statement.
🌐
Gitbooks
hamednourhani.gitbooks.io › typescript-book › content › docs › tips › null.html
null is bad · typescript-book
TypeScript team doesn't use null : TypeScript coding guidelines and it hasn't caused any problems. Douglas Crockford thinks null is a bad idea and we should all just use undefined · If your code base interacts with other APIs that might give you a null you check with == undefined (instead of ===).