絶対値を返します.
Math.abs(x)
absメソッドはxの絶対値を返します.
以下にabsメソッドを使用したサンプルコードを以下に示します.
<html>
<head>
<title>absメソッドのサンプルコード</title>
</head>
<body>
<script type="text/javascript" language="javascript">
document.write(Math.abs(10) + "<br />");
document.write(Math.abs(-10) + "<br />");
document.write(Math.abs(0) + "<br />");
document.write(Math.abs(-0) + "<br />");
document.write(Math.abs(NaN) + "<br />");
document.write(Math.abs(Infinity) + "<br />");
document.write(Math.abs(-Infinity) + "<br />");
</script>
</body>
</html>
サンプルコードの実行結果は以下のようになります.
10 10 0 0 NaN Infinity Infinity
スポンサード リンク