Check if foo variable exists - Javascript Data Type

Javascript examples for Data Type:Variable Scope

Description

Check if foo variable exists

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from w w  w .  j  a va 2 s .c o  m
var foo = 'some content'; //comment out this line to check
if (typeof foo !== 'undefined'){
console.log('Foo Exists');
}
else {
console.log('Foo No Exists');
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials