Math.max and Math.min NaN on undefined entry - Javascript Math

Javascript examples for Math:max

Description

Math.max and Math.min NaN on undefined entry

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() {//www .  j  a va2s  . co  m
var a = 5;
    var b = 10;
    var c = undefined;
    var defaultForMax = function (num) {
        return typeof num === 'number' ? num : -Infinity;
    };
    c = defaultForMax(c); // -Infinity
    console.log(c);
    console.log(Math.max(a, b, c)); // 10
    });

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

Related Tutorials