The NaN:- JavaScript


  • The NaN property represents "Not-a-Number" value. This property indicates that a value is not a legal number.
  • If you used string value instead of integer value in any of the statement, the statement will return NaN value.
  • The NaN property is the same as the Number.NaN property.
Code:-

  1. <!DOCTYPE html> 
  2. <html> 
  3.  
  4. <head> 
  5.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  6.  
  7.  <script> 
  8.   /*NaN property representing Not-A-Number. 
  9.     If you are trying to convert string to integer, returns NaN.*/ 
  10.  
  11.   function cal_fun() 
  12.   { 
  13.    var str = "Testing"; 
  14.    var num = parseInt(str); 
  15.    alert(num); 
  16.   } 
  17.  </script> 
  18.  
  19. </head> 
  20.  
  21. <body> 
  22.  <h2>NaN</h2> 
  23.  
  24.  <button onclick="cal_fun();">Convert to Integer</button> 
  25.  
  26. </body> 
  27.  
  28. </html>
The NaN:- JavaScript The NaN:- JavaScript Reviewed by Network security on November 11, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.