JavaScript/ Typescript object null check?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

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.
raja
Published on 24-Oct-2020 12:20:14
Advertisements