Javascript examples for Data Type:Variable Scope
Check if foo variable exists
<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>