JavaScript中的Math.abs()函数

Math对象的abs()函数接受一个数字并返回其绝对值。

语法

其语法如下

Math.abs(3)

示例

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result = Math.abs(3);
      document.write("Absolute value: "+result);
   </script>
</body>
</html>

输出结果

Absolute value: 3