JavaScript 中的 Math.abs() 函数

htmljavascriptweb developmentfront end technology

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

语法

其语法如下

Math.abs(3)

示例

<html>
<head>
   <title>JavaScript 示例</title>
</head>
<body>
   <script type="text/javascript">
      var result = Math.abs(3);
      document.write("绝对值:"+result);
   </script>
</body>
</html>

输出

绝对值:3

相关文章