From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../reference/global_objects/math/abs/index.html | 125 +++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/math/abs/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/math/abs') diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/abs/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/abs/index.html new file mode 100644 index 0000000000..13f5f96b79 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/math/abs/index.html @@ -0,0 +1,125 @@ +--- +title: Math.abs() +slug: Web/JavaScript/Reference/Global_Objects/Math/abs +translation_of: Web/JavaScript/Reference/Global_Objects/Math/abs +--- +
{{JSRef("Global_Objects", "Math")}}
+ +

Math.abs(x) 函数返回指定数字 “x“ 的绝对值。如下:

+ +

Math.abs(x)=|x|={xifx0-xifx<0{\mathtt{\operatorname{Math.abs}(x)}} = {|x|} = \begin{cases} x & \text{if} \quad x \geq 0 \\ -x & \text{if} \quad x < 0 \end{cases}

+ +

语法

+ +
Math.abs(x);
+ +

参数

+ +
+
x
+
一个数值
+
+ +

说明

+ +

由于 Math.abs()  Math 中的一个静态方法,你应该通过 Math.abs() 调用。(Math 不是构造器)

+ +

示例

+ +

Math.abs()函数的行为

+ +

传入一个非数字形式的字符串或者 undefined/empty 变量,将返回 NaN。传入 null 将返回 0。

+ +
Math.abs('-1');     // 1
+Math.abs(-2);       // 2
+Math.abs(null);     // 0
+Math.abs("string"); // NaN
+Math.abs();         // NaN
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
规范版本规范状态注解
ECMAScript 1st Edition. Implemented in JavaScript 1.0StandardInitial definition.
{{SpecName('ES5.1', '#sec-15.8.2.1', 'Math.abs')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-math.abs', 'Math.abs')}}{{Spec2('ES6')}} 
+ +

浏览器兼容性

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
+
+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf