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 | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/math/abs/index.html (limited to 'files/ja/web/javascript/reference/global_objects/math/abs/index.html') diff --git a/files/ja/web/javascript/reference/global_objects/math/abs/index.html b/files/ja/web/javascript/reference/global_objects/math/abs/index.html new file mode 100644 index 0000000000..f8ae38085c --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/math/abs/index.html @@ -0,0 +1,87 @@ +--- +title: Math.abs() +slug: Web/JavaScript/Reference/Global_Objects/Math/abs +tags: + - JavaScript + - Math + - Method + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Math/abs +--- +
{{JSRef}}
+ +

Math.abs() 関数は、数値の絶対値を返します。

+ +

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

+ +
{{EmbedInteractiveExample("pages/js/math-abs.html")}}
+ + + +

構文

+ +
Math.abs(x)
+ +

引数

+ +
+
x
+
数値です。
+
+ +

返値

+ +

与えられた数値の絶対値。

+ +

解説

+ +

abs()Math オブジェクトの静的メソッドなので、 Math オブジェクトを生成してメソッドとして使用するのではなく、常に Math.abs() として使用するようにしてください (Math はコンストラクターではありません)。

+ +

+ +

Math.abs() の動作

+ +

空のオブジェクト、複数のメンバーを持つ配列、数値でない文字列、 {{jsxref("undefined")}}、 空の変数を渡すと、 {{jsxref("NaN")}} を返します。 {{jsxref("null")}} を渡すと空文字列を返し、空の配列は 0 を返します。

+ +
Math.abs('-1');     // 1
+Math.abs(-2);       // 2
+Math.abs(null);     // 0
+Math.abs('');       // 0
+Math.abs([]);       // 0
+Math.abs([2]);      // 2
+Math.abs([1,2]);    // NaN
+Math.abs({});       // NaN
+Math.abs('string'); // NaN
+Math.abs();         // NaN
+
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-math.abs', 'Math.abs')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.builtins.Math.abs")}}

+ +

関連情報

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