How to check a not-defined variable in JavaScript?


To check a variable is ‘undefined’, you need to check using the following. If the result is “false”, it means the variable is not defined. Here, the variable results in “True” −

Example

Live Demo

<html>
   <body>
      <script>
         var points = 100;
            if(points){
               document.write("True");
            }else{
               document.write("False");
            }
      </script>
   </body>
</html>

Updated on: 15-Jun-2020

130 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements