Check for 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: 2020-06-15T05:26:32+05:30

228 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements