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
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-2-0.html
TypeScript: Documentation - TypeScript 2.0
In practical terms, strict null checking mode requires that all files in a compilation are null- and undefined-aware. TypeScript 2.0 implements a control flow-based type analysis for local variables and parameters. Previously, the type analysis performed for type guards was limited to if statements and ?: conditional expressions and didn’t include effects of assignments and control flow constructs such as return and break statements.
Discussions

How to check undefined in TypeScript - Stack Overflow
Correct however in the question ... return null. 2018-07-30T09:08:53.503Z+00:00 ... Can be misleading with the title of the post. I do second Todd on that one. 2019-10-21T13:37:23.923Z+00:00 ... but it has to be a string, so it can't be 0. Why bother typing if you don't trust your types? 2021-04-07T17:43:28.193Z+00:00 ... @Toxiro This is typescript. It can't be a number. so it's either an undefined string or a string. the simple if is the simplest way to check without any ... More on stackoverflow.com
🌐 stackoverflow.com
May 1, 2017
Object is possibly 'null' after null check.
const [map, setMap] = React.useState(null) ^ Here's the problem. Typescript is inferring the type of map here as null. i.e. it doesn't think map will every be anything other than null. You need to explicitly set map's type. Try something like this const [map, setMap] = React.useState(null) More on reddit.com
🌐 r/typescript
21
5
December 3, 2020
Is Null Checking Necessary in TypeScript for Runtime Safety?
Is your program going to work with a null value in that spot? <- focus on this More on reddit.com
🌐 r/reactjs
22
9
August 13, 2024
How to check variable for 0 or higher number?
Why not just do something like: if (typeof myval === 'number' && myval >= 0) { // do something } typeof myval === 'number' will make sure myval is a number (not null nor undefined), and myval >= 0 makes sure it is not NaN and a value greater or equal than 0 (no need to check if myval is NaN separately) More on reddit.com
🌐 r/typescript
24
9
May 23, 2022
🌐
Angular Wiki
angularjswiki.com › angular › how-to-check-both-null-or-undefined-in-typescript-or-angular
How To Check Both null or undefined in TypeScript/Angular | Angular Wiki
December 17, 2021 - different ways we can check both null or undefined in TypeScript or Angular. 1. By using simple if condition 2. By using TypeScript Nullish Coalescing & Optional chaining. 3. By using Array.include() function.
🌐
GitBook
basarat.gitbook.io › typescript › recap › null-undefined
Null vs. Undefined | TypeScript Deep Dive
August 18, 2020 - Recommend == null to check for both undefined or null. You generally don't want to make a distinction between the two. ... function foo(arg: string | null | undefined) { if (arg != null) { // arg must be a string as `!=` rules out both null ...
🌐
Tektutorialshub
tektutorialshub.com › home › typescript › null vs undefined in typescript
Null Vs Undefined in TypeScript - Tektutorialshub
March 15, 2023 - But they are neither false nor true. You can use typeof operator to check for undefined but not null as it returns “object”. You can use the == & === operator to check their values
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-determine-if-variable-is-undefined-or-null-in-javascript.php
How to Determine If Variable is Undefined or NULL in JavaScript
<script> var firstName; var lastName = null; // Try to get non existing DOM element var comment = document.getElementById('comment'); console.log(firstName); // Print: undefined console.log(lastName); // Print: null console.log(comment); // Print: null console.log(typeof firstName); // Print: undefined console.log(typeof lastName); // Print: object console.log(typeof comment); // Print: object console.log(null == undefined) // Print: true console.log(null === undefined) // Print: false /* Since null == undefined is true, the following statements will catch both null and undefined */ if(firstNa
🌐
Stack Abuse
stackabuse.com › javascript-check-if-variable-is-a-undefined-or-null
JavaScript: Check if Variable is undefined or null
March 29, 2023 - The typeof operator can additionally be used alongside the === operator to check if the type of a variable is equal to 'undefined' or 'null':
Find elsewhere
🌐
Cloudhadoop
cloudhadoop.com › home
How to check null or undefined of an object in Typescript Example
March 6, 2024 - The condition used to check null or undefined values in JavaScript is crucial. TypeScript, as a superset of JavaScript with added features like typing and assertions, allows every piece of code to function within its scope. ... The expression must evaluate to true or false. It evaluates to false for the following values. ... Let’s consider an example. if (obj !== undefined && obj !== null) { console.log("Object is Not Null"); }
🌐
Marius Schulz
mariusschulz.com › blog › null-checking-for-expression-operands-in-typescript
Null-Checking for Expression Operands in TypeScript — Marius Schulz
November 22, 2020 - Here's are the conditions under which TypeScript flags nullable expression operands as errors, quoted from the release notes: If either operand of a + operator is nullable, and neither operand is of type any or string.
🌐
Shinesolutions
shinesolutions.com › home › writing safer code with typescript strict null checks & type guards
Writing safer code with TypeScript strict null checks & type guards - Shine Solutions Group
January 6, 2017 - Suffice to say that any developer ... that was null or undefined will probably recognise these sorts of error message: Uncaught ReferenceError: foo is not defined Uncaught TypeError: window.foo is not a function · These errors happen at runtime when you’ve deployed your code already. Ideally, we want to prevent them when writing the code, not when we are running it. That’s what strictNullChecks compiler flag is for. Ideally, if you read the TypeScript manual before ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › check-if-an-array-is-empty-or-not-in-javascript
Check if an array is empty or not in JavaScript
July 11, 2025 - The length property can be used to get the length of the given array if it returns 0 then the length of the array is 0 means the given array is empty else the array have the elements.
🌐
Marius Schulz
mariusschulz.com › blog › typescript-2-2-null-checking-for-expression-operands
Home — Marius Schulz
March 10, 2017 - TypeScript 3.7 added support for the ?? operator, which is known as the nullish coalescing operator. We can use this operator to provide a fallback value for a value that might be null or undefined. ... Different approaches for declaring a global variable in TypeScript.
🌐
W3Schools
w3schools.com › typescript › typescript_null.php
TypeScript Null & Undefined
Nullish coalescing is another JavaScript feature that also works well with TypeScript's null handling. It allows writing expressions that have a fallback specifically when dealing with null or undefined. This is useful when other falsy values can occur in the expression but are still valid. It can be used with the ?? operator in an expression, similar to using the && operator. function printMileage(mileage: number | null | undefined) { console.log(`Mileage: ${mileage ??
🌐
Omarileon
omarileon.me › blog › typescript-null-undefined
mari. | How to Detect Null and Undefined in Your TypeScript Code
February 27, 2024 - The most straightforward way of checking is of course the equality operator. const myValue = maybeNullOrUndefined(); if (myValue === null) console.log('Null!'); if (myValue === undefined) console.log('Undefined!');
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › how-to-check-null-and-undefined-in-typescript
How to check null and undefined in TypeScript ? - GeeksforGeeks
July 23, 2025 - We can use typeof or '==' or '===' to check if a variable is null or undefined in typescript.
🌐
TutorialsPoint
tutorialspoint.com › javascript-typescript-object-null-check
JavaScript/ Typescript object null check?
June 18, 2024 - In this example below, we've assigned ... need to run the above code in node.js terminal to get the output. var value=null; if(!value) { console.log("This is null."); } else { console.log("This is not null."); }...