From 4ba2fc11c3ad0140b7628aa78fef27c58b8aab94 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Mon, 27 Sep 2021 00:08:45 +0900 Subject: 単項プラス、単項マイナスの変換準備 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reference/operators/unary_negation/index.html | 78 --------------------- .../reference/operators/unary_negation/index.md | 78 +++++++++++++++++++++ .../reference/operators/unary_plus/index.html | 80 ---------------------- .../reference/operators/unary_plus/index.md | 80 ++++++++++++++++++++++ 4 files changed, 158 insertions(+), 158 deletions(-) delete mode 100644 files/ja/web/javascript/reference/operators/unary_negation/index.html create mode 100644 files/ja/web/javascript/reference/operators/unary_negation/index.md delete mode 100644 files/ja/web/javascript/reference/operators/unary_plus/index.html create mode 100644 files/ja/web/javascript/reference/operators/unary_plus/index.md (limited to 'files/ja/web') diff --git a/files/ja/web/javascript/reference/operators/unary_negation/index.html b/files/ja/web/javascript/reference/operators/unary_negation/index.html deleted file mode 100644 index 0a7fe27e04..0000000000 --- a/files/ja/web/javascript/reference/operators/unary_negation/index.html +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: 単項マイナス (-) -slug: Web/JavaScript/Reference/Operators/Unary_negation -tags: - - JavaScript - - Language feature - - Operator - - Reference - - 演算子 - - 言語機能 -translation_of: Web/JavaScript/Reference/Operators/Unary_negation ---- -
{{jsSidebar("Operators")}}
- -

単項マイナス演算子 (-) はオペランドの前に置かれ、符号を反転します。

- -
{{EmbedInteractiveExample("pages/js/expressions-unary-negation.html")}}
- - - -

構文

- -
演算子: -x
-
- -

- -

数値の符号を反転

- -
const x = 3;
-const y = -x;
-
-// y = -3
-// x = 3
-
- -

数値以外の符号を反転

- -

単項マイナス演算子は、数値でないものを数値に変換することができます。

- -
const x = "4";
-const y = -x;
-
-// y = -4
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-unary-minus-operator', 'Unary negation operator')}}
- -

ブラウザーの互換性

- -

{{Compat("javascript.operators.unary_negation")}}

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/operators/unary_negation/index.md b/files/ja/web/javascript/reference/operators/unary_negation/index.md new file mode 100644 index 0000000000..0a7fe27e04 --- /dev/null +++ b/files/ja/web/javascript/reference/operators/unary_negation/index.md @@ -0,0 +1,78 @@ +--- +title: 単項マイナス (-) +slug: Web/JavaScript/Reference/Operators/Unary_negation +tags: + - JavaScript + - Language feature + - Operator + - Reference + - 演算子 + - 言語機能 +translation_of: Web/JavaScript/Reference/Operators/Unary_negation +--- +
{{jsSidebar("Operators")}}
+ +

単項マイナス演算子 (-) はオペランドの前に置かれ、符号を反転します。

+ +
{{EmbedInteractiveExample("pages/js/expressions-unary-negation.html")}}
+ + + +

構文

+ +
演算子: -x
+
+ +

+ +

数値の符号を反転

+ +
const x = 3;
+const y = -x;
+
+// y = -3
+// x = 3
+
+ +

数値以外の符号を反転

+ +

単項マイナス演算子は、数値でないものを数値に変換することができます。

+ +
const x = "4";
+const y = -x;
+
+// y = -4
+
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-unary-minus-operator', 'Unary negation operator')}}
+ +

ブラウザーの互換性

+ +

{{Compat("javascript.operators.unary_negation")}}

+ +

関連情報

+ + diff --git a/files/ja/web/javascript/reference/operators/unary_plus/index.html b/files/ja/web/javascript/reference/operators/unary_plus/index.html deleted file mode 100644 index 418686a5c1..0000000000 --- a/files/ja/web/javascript/reference/operators/unary_plus/index.html +++ /dev/null @@ -1,80 +0,0 @@ ---- -title: 単項プラス (+) -slug: Web/JavaScript/Reference/Operators/Unary_plus -tags: - - JavaScript - - Language feature - - Operator - - Reference -translation_of: Web/JavaScript/Reference/Operators/Unary_plus ---- -
{{jsSidebar("Operators")}}
- -

単項プラス演算子 (+) は、オペランドの前に置かれ、そのオペランドを評価し、それが数値以外の場合は数値に変換します。

- -
{{EmbedInteractiveExample("pages/js/expressions-unary-plus.html", "taller")}}
- - - -

- -
Operator: +x
-
- -

説明

- -

単項マイナス (-) も非数値を数値に変換できますが、単項プラスは数値に対して他の演算を行わないため、非数値を数値に変換する最も高速で好ましい方法です。これは、整数や浮動小数点の文字列表現や、非文字列値である truefalsenull を変換することができます。10進数と16進数(接頭辞 0x)の両形式の整数と負の数(16進数の負の数はサポートされていません)がサポートされています。BigInt 値に対してこの演算子を使用すると TypeError がスローされます。特定の値を解析できない場合は、{{jsxref("NaN")}} と評価されます。

- -

- -

数値での使い方

- -
const x = 1;
-const y = -1;
-
-console.log(+x);
-// 1
-console.log(+y);
-// -1
- -

数値以外での使い方

- -
+true  // 1
-+false // 0
-+null  // 0
-+function(val){ return val } // NaN
-+1n    //  BigInt 値は数値に変換できないためエラーになります
-
- -

仕様

- - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-unary-plus-operator', 'Unary plus operator')}}
- -

ブラウザの互換性

- - - -

{{Compat("javascript.operators.unary_plus")}}

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/operators/unary_plus/index.md b/files/ja/web/javascript/reference/operators/unary_plus/index.md new file mode 100644 index 0000000000..418686a5c1 --- /dev/null +++ b/files/ja/web/javascript/reference/operators/unary_plus/index.md @@ -0,0 +1,80 @@ +--- +title: 単項プラス (+) +slug: Web/JavaScript/Reference/Operators/Unary_plus +tags: + - JavaScript + - Language feature + - Operator + - Reference +translation_of: Web/JavaScript/Reference/Operators/Unary_plus +--- +
{{jsSidebar("Operators")}}
+ +

単項プラス演算子 (+) は、オペランドの前に置かれ、そのオペランドを評価し、それが数値以外の場合は数値に変換します。

+ +
{{EmbedInteractiveExample("pages/js/expressions-unary-plus.html", "taller")}}
+ + + +

+ +
Operator: +x
+
+ +

説明

+ +

単項マイナス (-) も非数値を数値に変換できますが、単項プラスは数値に対して他の演算を行わないため、非数値を数値に変換する最も高速で好ましい方法です。これは、整数や浮動小数点の文字列表現や、非文字列値である truefalsenull を変換することができます。10進数と16進数(接頭辞 0x)の両形式の整数と負の数(16進数の負の数はサポートされていません)がサポートされています。BigInt 値に対してこの演算子を使用すると TypeError がスローされます。特定の値を解析できない場合は、{{jsxref("NaN")}} と評価されます。

+ +

+ +

数値での使い方

+ +
const x = 1;
+const y = -1;
+
+console.log(+x);
+// 1
+console.log(+y);
+// -1
+ +

数値以外での使い方

+ +
+true  // 1
++false // 0
++null  // 0
++function(val){ return val } // NaN
++1n    //  BigInt 値は数値に変換できないためエラーになります
+
+ +

仕様

+ + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-unary-plus-operator', 'Unary plus operator')}}
+ +

ブラウザの互換性

+ + + +

{{Compat("javascript.operators.unary_plus")}}

+ +

関連情報

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