How to use Math.max in JavaScript

  • The Math.max() function will return the largest of non zero numbers.
  • If no arguments are provided, the result is Infinity.
  • If at least one of arguments cannot be converted to a number, the result is NaN.

Syntax 
Math.max([value1[, value2[,...]


Code:-
  • <!DOCTYPE html> 
    1. <html> 
    2.  
    3. <head> 
    4.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
    5. </head> 
    6.  
    7. <body> 
    8.  <h1>Math.max()</h1> 
    9.  
    10.  <input type="button" onclick="max_val();" value="Get Max"> 
    11.  
    12.  <script> 
    13.   function max_val() 
    14.   { 
    15.    alert("Max : " + Math.max(3, 4, 5, 6, -5)); 
    16.   } 
    17.  </script> 
    18.  
    19. </body> 
    20.  
    21. </html>
    How to use Math.max in JavaScript How to use Math.max in JavaScript Reviewed by Network security on July 02, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.