Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

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

With JavaScript, I want to find whether a variable is 'null' or 'undefined'. The following is my code, but I am not sure about it:

function isEmpty(age) {
   return (age === undefined || age == null) ? true : false;

}


1 Answer
Swarali Sree

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>
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.