How do I check for null values in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To check for null values in JavaScript, you need to check the variable value with null. Use the JavaScript strict equality operator to achieve this.

Example

You can try to run the following code to check whether the value of the variable is null or not −

<html>
   <head>
      <title>JavaScript Strict Equality Operator</title>
   </head>
   <body>
      <script>
         var a = 10;
         if(a === null) {
            document.write("Value is null");
         } else {
            document.write("Value is not null");
         }
      </script>
   </body>
</html>
raja
Published on 16-Feb-2018 08:30:17
Advertisements