Open In App

Difference Between null & undefined in TypeScript

Last Updated : 22 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The null and undefined are the different data types in TypeScript and both of them are used to represent the empty values. But, there are still some key differences between them as listed in the below table.

null

undefined

It denotes the intentional absence of a value.

It represents the absence of a value due to the absence of initialization.

It can be assigned manually as a value to the variables.

It is the default value for the uninitialized variables.

It is used with the function which returns non-meaningful results.

It is used as the default value of the variables before assigning them with a value.

To check for the null value you need to use the strict equality (===) or strict inequality (!==) operator.

To check for undefined values you can simply use the strict equality(===) or loose equality(==) operator.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads