最大値を返します.
Math.max(x1, x2, ..., xn)
maxメソッドは引数で指定された数値の最大値を返します.
以下にmaxメソッドを使用したサンプルコードを示します.
<html>
<head>
<title>maxメソッドのサンプルコード</title>
</head>
<body>
<script type="text/javascript" language="javascript">
document.write(Math.max(1, 2, 3, 4, 5) + "<br />");
document.write(Math.max(-1, -2, -3, -4, -5) + "<br />");
document.write(Math.max("1", "2", "3", "4") + "<br />");
document.write(Math.max("N") + "<br />");
document.write(Math.max() + "<br />");
</script>
</body>
</html>
サンプルコードの実行結果は以下のようになります.
5 -1 4 NaN -Infinity
スポンサード リンク