Computer >> Computer tutorials >  >> Programming >> Javascript

JavaScript/ Typescript object null check?


For null check, you can use ! condition.

Example

Following is the code −

var value=null;
if(!value) {
   console.log("This is null.");
} else {
   console.log("This is not null.");
}

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo305.js.

Output

This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo305.js
This is null.