From 1a9dcfb7fcefa92627be0033f0edaf609c5444bf Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Mon, 27 Sep 2021 22:07:28 +0900 Subject: JavaScript の等価演算子を変換準備 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reference/operators/equality/index.html | 126 --------------------- .../reference/operators/equality/index.md | 126 +++++++++++++++++++++ .../reference/operators/inequality/index.html | 98 ---------------- .../reference/operators/inequality/index.md | 98 ++++++++++++++++ .../reference/operators/strict_equality/index.html | 106 ----------------- .../reference/operators/strict_equality/index.md | 106 +++++++++++++++++ .../operators/strict_inequality/index.html | 100 ---------------- .../reference/operators/strict_inequality/index.md | 100 ++++++++++++++++ 8 files changed, 430 insertions(+), 430 deletions(-) delete mode 100644 files/ja/web/javascript/reference/operators/equality/index.html create mode 100644 files/ja/web/javascript/reference/operators/equality/index.md delete mode 100644 files/ja/web/javascript/reference/operators/inequality/index.html create mode 100644 files/ja/web/javascript/reference/operators/inequality/index.md delete mode 100644 files/ja/web/javascript/reference/operators/strict_equality/index.html create mode 100644 files/ja/web/javascript/reference/operators/strict_equality/index.md delete mode 100644 files/ja/web/javascript/reference/operators/strict_inequality/index.html create mode 100644 files/ja/web/javascript/reference/operators/strict_inequality/index.md (limited to 'files') diff --git a/files/ja/web/javascript/reference/operators/equality/index.html b/files/ja/web/javascript/reference/operators/equality/index.html deleted file mode 100644 index 25a1e23347..0000000000 --- a/files/ja/web/javascript/reference/operators/equality/index.html +++ /dev/null @@ -1,126 +0,0 @@ ---- -title: 等価 (==) -slug: Web/JavaScript/Reference/Operators/Equality -tags: - - JavaScript - - Language feature - - Operator - - Reference - - 演算子 - - 言語機能 -translation_of: Web/JavaScript/Reference/Operators/Equality ---- -
{{jsSidebar("Operators")}}
- -

等価演算子 (==) は、二つのオペランドが等しいことを検査し、論理値で結果を返します 厳密等価演算子とは異なり、オペランドの型が異なる場合には型の変換を試みてから比較を行います。

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

構文

- -
x == y
-
- -

解説

- -

等価演算子 (== および !=) は、抽象等価比較アルゴリズムを使用して二つのオペランドを比較します。これは、およそ次のようにまとめることができます。

- - - -

この演算子と厳密等価 (===) 演算子の最も顕著な違いは、厳密等価演算子が型変換を試みない点です。厳密等価演算は、オペランドの型が異なる場合は常に異なるものと見なします。

- -

- -

型変換がない場合の比較

- -
1 == 1;              // true
-"hello" == "hello";  // true
- -

型変換がある場合の比較

- -
"1" ==  1;            // true
-1 == "1";             // true
-0 == false;           // true
-0 == null;            // false
-0 == undefined;       // false
-null == undefined;    // true
-
-const number1 = new Number(3);
-const number2 = new Number(3);
-number1 == 3;         // true
-number1 == number2;   // false
- -

オブジェクトの比較

- -
const object1 = {"key": "value"}
-const object2 = {"key": "value"};
-
-object1 == object2 // false
-object2 == object2 // true
- -

文字列と String オブジェクトの比較

- -

new String() を使用して構築された文字列はオブジェクトであることに注意してください。文字列リテラルとの比較を行うと、 String オブジェクトは文字列リテラルに変換され、その中身が比較されます。ただし、両方のオペランドが String オブジェクトであった場合は、オブジェクトとして比較され、同じオブジェクトを参照している場合だけ比較に成功します。

- -
const string1 = "hello";
-const string2 = String("hello");
-const string3 = new String("hello");
-const string4 = new String("hello");
-
-console.log(string1 == string2); // true
-console.log(string1 == string3); // true
-console.log(string2 == string3); // true
-console.log(string3 == string4); // false
-console.log(string4 == string4); // true
- -

Date と文字列の比較

- -
const d = new Date('December 17, 1995 03:24:00');
-const s = d.toString(); // for example: "Sun Dec 17 1995 03:24:00 GMT-0800 (Pacific Standard Time)"
-console.log(d == s);    //true
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-equality-operators', 'Equality operators')}}
- -

ブラウザーの互換性

- -

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

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/operators/equality/index.md b/files/ja/web/javascript/reference/operators/equality/index.md new file mode 100644 index 0000000000..25a1e23347 --- /dev/null +++ b/files/ja/web/javascript/reference/operators/equality/index.md @@ -0,0 +1,126 @@ +--- +title: 等価 (==) +slug: Web/JavaScript/Reference/Operators/Equality +tags: + - JavaScript + - Language feature + - Operator + - Reference + - 演算子 + - 言語機能 +translation_of: Web/JavaScript/Reference/Operators/Equality +--- +
{{jsSidebar("Operators")}}
+ +

等価演算子 (==) は、二つのオペランドが等しいことを検査し、論理値で結果を返します 厳密等価演算子とは異なり、オペランドの型が異なる場合には型の変換を試みてから比較を行います。

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

構文

+ +
x == y
+
+ +

解説

+ +

等価演算子 (== および !=) は、抽象等価比較アルゴリズムを使用して二つのオペランドを比較します。これは、およそ次のようにまとめることができます。

+ + + +

この演算子と厳密等価 (===) 演算子の最も顕著な違いは、厳密等価演算子が型変換を試みない点です。厳密等価演算は、オペランドの型が異なる場合は常に異なるものと見なします。

+ +

+ +

型変換がない場合の比較

+ +
1 == 1;              // true
+"hello" == "hello";  // true
+ +

型変換がある場合の比較

+ +
"1" ==  1;            // true
+1 == "1";             // true
+0 == false;           // true
+0 == null;            // false
+0 == undefined;       // false
+null == undefined;    // true
+
+const number1 = new Number(3);
+const number2 = new Number(3);
+number1 == 3;         // true
+number1 == number2;   // false
+ +

オブジェクトの比較

+ +
const object1 = {"key": "value"}
+const object2 = {"key": "value"};
+
+object1 == object2 // false
+object2 == object2 // true
+ +

文字列と String オブジェクトの比較

+ +

new String() を使用して構築された文字列はオブジェクトであることに注意してください。文字列リテラルとの比較を行うと、 String オブジェクトは文字列リテラルに変換され、その中身が比較されます。ただし、両方のオペランドが String オブジェクトであった場合は、オブジェクトとして比較され、同じオブジェクトを参照している場合だけ比較に成功します。

+ +
const string1 = "hello";
+const string2 = String("hello");
+const string3 = new String("hello");
+const string4 = new String("hello");
+
+console.log(string1 == string2); // true
+console.log(string1 == string3); // true
+console.log(string2 == string3); // true
+console.log(string3 == string4); // false
+console.log(string4 == string4); // true
+ +

Date と文字列の比較

+ +
const d = new Date('December 17, 1995 03:24:00');
+const s = d.toString(); // for example: "Sun Dec 17 1995 03:24:00 GMT-0800 (Pacific Standard Time)"
+console.log(d == s);    //true
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-equality-operators', 'Equality operators')}}
+ +

ブラウザーの互換性

+ +

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

+ +

関連情報

+ + diff --git a/files/ja/web/javascript/reference/operators/inequality/index.html b/files/ja/web/javascript/reference/operators/inequality/index.html deleted file mode 100644 index aab622a884..0000000000 --- a/files/ja/web/javascript/reference/operators/inequality/index.html +++ /dev/null @@ -1,98 +0,0 @@ ---- -title: 不等価 (!=) -slug: Web/JavaScript/Reference/Operators/Inequality -tags: - - JavaScript - - Language feature - - Operator - - Reference -translation_of: Web/JavaScript/Reference/Operators/Inequality ---- -
{{jsSidebar("Operators")}}
- -

不等価演算子 (!=) は、2つのオペランドが等しくないかをチェックし、ブール値の結果を返します。厳密不等価演算子とは異なり、異なる型のオペランドを変換して比較を行おうとします。

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

構文

- -
x != y
- -

説明

- -

不等価演算子は、そのオペランドが等しくないかどうかをチェックします。これは等価演算子の否定なので、次の2行は常に同じ結果になります。

- -
x != y
-
-!(x == y)
- -

比較アルゴリズムの詳細については、等価演算子のページを参照して下さい。

- -

等価演算子と同様に、不等価演算子は異なる型のオペランドを変換して比較しようとします。

- -
3 != "3"; // false
- -

これを防止し、異なる型が異なる結果を返すようにするには、代わりに厳密不等価演算子を使用します:

- -
3 !== "3"; // true
- -

- -

型変換なしの比較

- -
1 != 2;              // true
-"hello" != "hola";   // true
-
-1 != 1;              // false
-"hello" != "hello";  // false
- -

型変換ありの比較

- -
"1" !=  1;            // false
-1 != "1";             // false
-0 != false;           // false
-0 != null;            // true
-0 != undefined;       // true
-null != undefined;    // false
-
-const number1 = new Number(3);
-const number2 = new Number(3);
-number1 != 3;         // false
-number1 != number2;   // true
- -

オブジェクトの比較

- -
const object1 = {"key": "value"}
-const object2 = {"key": "value"};
-
-object1 != object2 // true
-object2 != object2 // false
- -

仕様

- - - - - - - - - - -
仕様
{{SpecName('ESDraft', '#sec-equality-operators', 'Equality operators')}}
- -

ブラウザー実装状況

- - - -

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

- -

関連項目

- - diff --git a/files/ja/web/javascript/reference/operators/inequality/index.md b/files/ja/web/javascript/reference/operators/inequality/index.md new file mode 100644 index 0000000000..aab622a884 --- /dev/null +++ b/files/ja/web/javascript/reference/operators/inequality/index.md @@ -0,0 +1,98 @@ +--- +title: 不等価 (!=) +slug: Web/JavaScript/Reference/Operators/Inequality +tags: + - JavaScript + - Language feature + - Operator + - Reference +translation_of: Web/JavaScript/Reference/Operators/Inequality +--- +
{{jsSidebar("Operators")}}
+ +

不等価演算子 (!=) は、2つのオペランドが等しくないかをチェックし、ブール値の結果を返します。厳密不等価演算子とは異なり、異なる型のオペランドを変換して比較を行おうとします。

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

構文

+ +
x != y
+ +

説明

+ +

不等価演算子は、そのオペランドが等しくないかどうかをチェックします。これは等価演算子の否定なので、次の2行は常に同じ結果になります。

+ +
x != y
+
+!(x == y)
+ +

比較アルゴリズムの詳細については、等価演算子のページを参照して下さい。

+ +

等価演算子と同様に、不等価演算子は異なる型のオペランドを変換して比較しようとします。

+ +
3 != "3"; // false
+ +

これを防止し、異なる型が異なる結果を返すようにするには、代わりに厳密不等価演算子を使用します:

+ +
3 !== "3"; // true
+ +

+ +

型変換なしの比較

+ +
1 != 2;              // true
+"hello" != "hola";   // true
+
+1 != 1;              // false
+"hello" != "hello";  // false
+ +

型変換ありの比較

+ +
"1" !=  1;            // false
+1 != "1";             // false
+0 != false;           // false
+0 != null;            // true
+0 != undefined;       // true
+null != undefined;    // false
+
+const number1 = new Number(3);
+const number2 = new Number(3);
+number1 != 3;         // false
+number1 != number2;   // true
+ +

オブジェクトの比較

+ +
const object1 = {"key": "value"}
+const object2 = {"key": "value"};
+
+object1 != object2 // true
+object2 != object2 // false
+ +

仕様

+ + + + + + + + + + +
仕様
{{SpecName('ESDraft', '#sec-equality-operators', 'Equality operators')}}
+ +

ブラウザー実装状況

+ + + +

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

+ +

関連項目

+ + diff --git a/files/ja/web/javascript/reference/operators/strict_equality/index.html b/files/ja/web/javascript/reference/operators/strict_equality/index.html deleted file mode 100644 index 436a6d0899..0000000000 --- a/files/ja/web/javascript/reference/operators/strict_equality/index.html +++ /dev/null @@ -1,106 +0,0 @@ ---- -title: 厳密等価 (===) -slug: Web/JavaScript/Reference/Operators/Strict_equality -tags: - - JavaScript - - Language feature - - Operator - - Reference - - 演算子 - - 言語機能 -translation_of: Web/JavaScript/Reference/Operators/Strict_equality ---- -
{{jsSidebar("Operators")}}
- -

厳密等価演算子 (===) は、二つのオペランドが等しいことを検査し、論理値で結果を返します 等価演算子とは異なり、厳密等価演算子はオペランドの型が異なる場合、常に異なるものと判断します。

- -
{{EmbedInteractiveExample("pages/js/expressions-strict-equality.html")}}
- - - -

構文

- -
x === y
- -

解説

- -

厳密等価演算子 (=== および !==) は、厳密等価比較アルゴリズムを使用して二つのオペランドを比較します。

- - - -

この演算子と等価 (==) 演算子の最も顕著な違いは、オペランドの型が異なる場合、 == 演算子は比較前に同じ型に変換しようとすることです。

- -

- -

オペランドが同じ型である場合の比較

- -
console.log("hello" === "hello");   // true
-console.log("hello" === "hola");    // false
-
-console.log(3 === 3);               // true
-console.log(3 === 4);               // false
-
-console.log(true === true);         // true
-console.log(true === false);        // false
-
-console.log(null === null);         // true
- -

オペランドが異なる方である場合の比較

- -
console.log("3" === 3);           // false
-
-console.log(true === 1);          // false
-
-console.log(null === undefined);  // false
- -

オブジェクトの比較

- -
const object1 = {
-  name: "hello"
-}
-
-const object2 = {
-  name: "hello"
-}
-
-console.log(object1 === object2);  // false
-console.log(object1 === object1);  // true
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-equality-operators', 'Equality operators')}}
- -

ブラウザーの互換性

- -

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

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/operators/strict_equality/index.md b/files/ja/web/javascript/reference/operators/strict_equality/index.md new file mode 100644 index 0000000000..436a6d0899 --- /dev/null +++ b/files/ja/web/javascript/reference/operators/strict_equality/index.md @@ -0,0 +1,106 @@ +--- +title: 厳密等価 (===) +slug: Web/JavaScript/Reference/Operators/Strict_equality +tags: + - JavaScript + - Language feature + - Operator + - Reference + - 演算子 + - 言語機能 +translation_of: Web/JavaScript/Reference/Operators/Strict_equality +--- +
{{jsSidebar("Operators")}}
+ +

厳密等価演算子 (===) は、二つのオペランドが等しいことを検査し、論理値で結果を返します 等価演算子とは異なり、厳密等価演算子はオペランドの型が異なる場合、常に異なるものと判断します。

+ +
{{EmbedInteractiveExample("pages/js/expressions-strict-equality.html")}}
+ + + +

構文

+ +
x === y
+ +

解説

+ +

厳密等価演算子 (=== および !==) は、厳密等価比較アルゴリズムを使用して二つのオペランドを比較します。

+ + + +

この演算子と等価 (==) 演算子の最も顕著な違いは、オペランドの型が異なる場合、 == 演算子は比較前に同じ型に変換しようとすることです。

+ +

+ +

オペランドが同じ型である場合の比較

+ +
console.log("hello" === "hello");   // true
+console.log("hello" === "hola");    // false
+
+console.log(3 === 3);               // true
+console.log(3 === 4);               // false
+
+console.log(true === true);         // true
+console.log(true === false);        // false
+
+console.log(null === null);         // true
+ +

オペランドが異なる方である場合の比較

+ +
console.log("3" === 3);           // false
+
+console.log(true === 1);          // false
+
+console.log(null === undefined);  // false
+ +

オブジェクトの比較

+ +
const object1 = {
+  name: "hello"
+}
+
+const object2 = {
+  name: "hello"
+}
+
+console.log(object1 === object2);  // false
+console.log(object1 === object1);  // true
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-equality-operators', 'Equality operators')}}
+ +

ブラウザーの互換性

+ +

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

+ +

関連情報

+ + diff --git a/files/ja/web/javascript/reference/operators/strict_inequality/index.html b/files/ja/web/javascript/reference/operators/strict_inequality/index.html deleted file mode 100644 index c74ae24677..0000000000 --- a/files/ja/web/javascript/reference/operators/strict_inequality/index.html +++ /dev/null @@ -1,100 +0,0 @@ ---- -title: 厳密不等価 (!==) -slug: Web/JavaScript/Reference/Operators/Strict_inequality -tags: - - JavaScript - - Language feature - - Operator - - Reference - - 演算子 - - 言語機能 -translation_of: Web/JavaScript/Reference/Operators/Strict_inequality ---- -
{{jsSidebar("Operators")}}
- -

厳密不等価演算子 (!==) は、二つのオペランドが等しくないことを検査し、論理値で結果を返します 不等価演算子とは異なり、厳密不等価演算子はオペランドの型が異なる場合、常に異なると判断します。

- -
{{EmbedInteractiveExample("pages/js/expressions-strict-equality.html")}}
- - - -

構文

- -
x !== y
- -

解説

- -

厳密不等価演算子は、オペランドが等しくないことを検査します。これは厳密等価演算子の逆に当たるので、以下の2行は常に同じ結果を生み出します。

- -
x !== y
-
-!(x === y)
- -

比較アルゴリズムの詳細については、厳密等価演算子のページをご覧ください。

- -

厳密等価演算子とと同様に、厳密不等価演算子はオペランドの型が異なると、常に異なるものと見なします。

- -
3 !== "3"; // true
- -

- -

オペランドが同じ型である場合の比較

- -
console.log("hello" !== "hello");   // false
-console.log("hello" !== "hola");    // true
-
-console.log(3 !== 3);               // false
-console.log(3 !== 4);               // true
-
-console.log(true !== true);         // false
-console.log(true !== false);        // true
-
-console.log(null !== null);         // false
- -

オペランドが異なる方である場合の比較

- -
console.log("3" !== 3);           // true
-
-console.log(true !== 1);          // true
-
-console.log(null !== undefined);  // true
- -

オブジェクトの比較

- -
const object1 = {
-  name: "hello"
-}
-
-const object2 = {
-  name: "hello"
-}
-
-console.log(object1 !== object2);  // true
-console.log(object1 !== object1);  // false
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-equality-operators', 'Equality operators')}}
- -

ブラウザーの互換性

- -

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

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/operators/strict_inequality/index.md b/files/ja/web/javascript/reference/operators/strict_inequality/index.md new file mode 100644 index 0000000000..c74ae24677 --- /dev/null +++ b/files/ja/web/javascript/reference/operators/strict_inequality/index.md @@ -0,0 +1,100 @@ +--- +title: 厳密不等価 (!==) +slug: Web/JavaScript/Reference/Operators/Strict_inequality +tags: + - JavaScript + - Language feature + - Operator + - Reference + - 演算子 + - 言語機能 +translation_of: Web/JavaScript/Reference/Operators/Strict_inequality +--- +
{{jsSidebar("Operators")}}
+ +

厳密不等価演算子 (!==) は、二つのオペランドが等しくないことを検査し、論理値で結果を返します 不等価演算子とは異なり、厳密不等価演算子はオペランドの型が異なる場合、常に異なると判断します。

+ +
{{EmbedInteractiveExample("pages/js/expressions-strict-equality.html")}}
+ + + +

構文

+ +
x !== y
+ +

解説

+ +

厳密不等価演算子は、オペランドが等しくないことを検査します。これは厳密等価演算子の逆に当たるので、以下の2行は常に同じ結果を生み出します。

+ +
x !== y
+
+!(x === y)
+ +

比較アルゴリズムの詳細については、厳密等価演算子のページをご覧ください。

+ +

厳密等価演算子とと同様に、厳密不等価演算子はオペランドの型が異なると、常に異なるものと見なします。

+ +
3 !== "3"; // true
+ +

+ +

オペランドが同じ型である場合の比較

+ +
console.log("hello" !== "hello");   // false
+console.log("hello" !== "hola");    // true
+
+console.log(3 !== 3);               // false
+console.log(3 !== 4);               // true
+
+console.log(true !== true);         // false
+console.log(true !== false);        // true
+
+console.log(null !== null);         // false
+ +

オペランドが異なる方である場合の比較

+ +
console.log("3" !== 3);           // true
+
+console.log(true !== 1);          // true
+
+console.log(null !== undefined);  // true
+ +

オブジェクトの比較

+ +
const object1 = {
+  name: "hello"
+}
+
+const object2 = {
+  name: "hello"
+}
+
+console.log(object1 !== object2);  // true
+console.log(object1 !== object1);  // false
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-equality-operators', 'Equality operators')}}
+ +

ブラウザーの互換性

+ +

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

+ +

関連情報

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