How to determine if a variable is 'undefined' or 'null'?


On getting the result of the following, you can find whether a variable is null or undefined. If the result is “false”, it means the variable is null and undefined.

Here, the variable results in “True” −

<html>
   <body>
      <script>
         var age = 10;

         if(age) {
            document.write("True");
         } else {
            document.write("False");
         }
      </script>
   </body>
</html>

Swarali Sree
Swarali Sree

I love thought experiments.

Updated on: 15-Jun-2020

532 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements