Put a variable check inside a string - Javascript Data Type

Javascript examples for Data Type:undefined

Description

Put a variable check inside a string

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 v a 2 s  . co m*/
var variable = true;
var mystring = 'The variable ' + (typeof variable !== 'undefined' ? 'exists' : 'doesn\'t exist');
console.log(mystring);
    }

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

Related Tutorials