How to check for “undefined” variable in JavaScript?

JavascriptWeb DevelopmentFront End Technology

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

Here, the variable results in “True”

Example

Live Demo
<html>
   <body>
   
      <script>
         var res = 10;

         if(res) {
            document.write("True");
         } else {
            document.write("False");
         }
      </script>
      
    </body>
</html>
raja
Published on 22-Jan-2018 11:58:26
Advertisements