Assign undefined to a variable - Javascript Data Type

Javascript examples for Data Type:undefined

Description

Assign undefined to a variable

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <button onclick="myFunction()">Click me</button> 
      <!-- <input type="text" id="demo"></input> --> 
      <script>
function myFunction() {/*from www  . j  a v  a  2 s  .  c  o  m*/
    var message = undefined;
    
    if (document.getElementById("demo"))
        message = document.getElementById("demo").value;
    if ( message ) 
        console.log(message);
    else 
        console.log("undefined");
}

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

Related Tutorials