From 01b0e12ba27b5069248fd09235e9a7143915ee30 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:02:49 +0800 Subject: remove `notranslate` class in zh-CN --- .../reference/operators/addition/index.html | 6 +-- .../operators/addition_assignment/index.html | 4 +- .../reference/operators/assignment/index.html | 4 +- .../reference/operators/await/index.html | 8 ++-- .../reference/operators/bitwise_and/index.html | 8 ++-- .../operators/bitwise_and_assignment/index.html | 4 +- .../reference/operators/bitwise_not/index.html | 8 ++-- .../reference/operators/bitwise_or/index.html | 8 ++-- .../operators/bitwise_or_assignment/index.html | 4 +- .../reference/operators/bitwise_xor/index.html | 8 ++-- .../operators/bitwise_xor_assignment/index.html | 4 +- .../reference/operators/decrement/index.html | 6 +-- .../reference/operators/delete/index.html | 28 ++++++------- .../reference/operators/division/index.html | 6 +-- .../operators/division_assignment/index.html | 4 +- .../reference/operators/equality/index.html | 12 +++--- .../reference/operators/exponentiation/index.html | 12 +++--- .../operators/exponentiation_assignment/index.html | 4 +- .../reference/operators/greater_than/index.html | 12 +++--- .../operators/greater_than_or_equal/index.html | 12 +++--- .../javascript/reference/operators/in/index.html | 14 +++---- .../reference/operators/increment/index.html | 6 +-- .../reference/operators/inequality/index.html | 14 +++---- .../reference/operators/instanceof/index.html | 12 +++--- .../reference/operators/left_shift/index.html | 6 +-- .../operators/left_shift_assignment/index.html | 4 +- .../reference/operators/less_than/index.html | 12 +++--- .../operators/less_than_or_equal/index.html | 12 +++--- .../reference/operators/logical_and/index.html | 20 +++++----- .../operators/logical_and_assignment/index.html | 8 ++-- .../reference/operators/logical_not/index.html | 10 ++--- .../logical_nullish_assignment/index.html | 8 ++-- .../reference/operators/logical_or/index.html | 20 +++++----- .../reference/operators/multiplication/index.html | 8 ++-- .../operators/multiplication_assignment/index.html | 4 +- .../javascript/reference/operators/new/index.html | 20 +++++----- .../nullish_coalescing_operator/index.html | 18 ++++----- .../operators/optional_chaining/index.html | 28 ++++++------- .../reference/operators/remainder/index.html | 8 ++-- .../operators/remainder_assignment/index.html | 4 +- .../reference/operators/right_shift/index.html | 8 ++-- .../operators/right_shift_assignment/index.html | 4 +- .../reference/operators/spread_syntax/index.html | 36 ++++++++--------- .../reference/operators/strict_equality/index.html | 8 ++-- .../operators/strict_inequality/index.html | 12 +++--- .../reference/operators/subtraction/index.html | 6 +-- .../operators/subtraction_assignment/index.html | 4 +- .../reference/operators/super/index.html | 12 +++--- .../javascript/reference/operators/this/index.html | 46 +++++++++++----------- .../reference/operators/typeof/index.html | 20 +++++----- .../reference/operators/unary_negation/index.html | 6 +-- .../reference/operators/unary_plus/index.html | 6 +-- .../operators/unsigned_right_shift/index.html | 8 ++-- .../unsigned_right_shift_assignment/index.html | 4 +- 54 files changed, 289 insertions(+), 289 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/operators') diff --git a/files/zh-cn/web/javascript/reference/operators/addition/index.html b/files/zh-cn/web/javascript/reference/operators/addition/index.html index c3726a9413..db323029cc 100644 --- a/files/zh-cn/web/javascript/reference/operators/addition/index.html +++ b/files/zh-cn/web/javascript/reference/operators/addition/index.html @@ -16,14 +16,14 @@ original_slug: Web/JavaScript/Reference/Operators/相加

语法

-
表达式: x + y
+
表达式: x + y
 

示例

数字的相加运算

-
// Number + Number -> addition
+
// Number + Number -> addition
 1 + 2 // 3
 
 // Boolean + Number -> addition
@@ -35,7 +35,7 @@ false + false // 0
 
 

字符串相加运算

-
// String + String -> concatenation
+
// String + String -> concatenation
 'foo' + 'bar' // "foobar"
 
 // Number + String -> concatenation
diff --git a/files/zh-cn/web/javascript/reference/operators/addition_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/addition_assignment/index.html
index 9469f0f0b7..5732d5c473 100644
--- a/files/zh-cn/web/javascript/reference/operators/addition_assignment/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/addition_assignment/index.html
@@ -17,14 +17,14 @@ translation_of: Web/JavaScript/Reference/Operators/Addition_assignment
 
 

Syntax

-
Operator: x += y
+
Operator: x += y
 Meaning:  x  = x + y

Examples

Using addition assignment

-
// Assuming the following variables
+
// Assuming the following variables
 //  foo = 'foo'
 //  bar = 5
 //  baz = true
diff --git a/files/zh-cn/web/javascript/reference/operators/assignment/index.html b/files/zh-cn/web/javascript/reference/operators/assignment/index.html
index 8c981fe11e..b03fcf3224 100644
--- a/files/zh-cn/web/javascript/reference/operators/assignment/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/assignment/index.html
@@ -21,14 +21,14 @@ translation_of: Web/JavaScript/Reference/Operators/Assignment
 
 

语法

-
Operator: x = y
+
Operator: x = y
 

示例

简单赋值和链式赋值

-
// 假设已经存在以下变量
+
// 假设已经存在以下变量
 //  x = 5
 //  y = 10
 //  z = 25
diff --git a/files/zh-cn/web/javascript/reference/operators/await/index.html b/files/zh-cn/web/javascript/reference/operators/await/index.html
index 0183f4d7ae..8b07b23e41 100644
--- a/files/zh-cn/web/javascript/reference/operators/await/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/await/index.html
@@ -15,7 +15,7 @@ translation_of: Web/JavaScript/Reference/Operators/await
 
 

语法

-
[返回值] = await 表达式;
+
[返回值] = await 表达式;
表达式
@@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Operators/await

如果一个 Promise 被传递给一个 await 操作符,await 将等待 Promise 正常处理完成并返回其处理结果。

-
function resolveAfter2Seconds(x) {
+
function resolveAfter2Seconds(x) {
   return new Promise(resolve => {
     setTimeout(() => {
       resolve(x);
@@ -56,7 +56,7 @@ f1();
 
 

如果该值不是一个 Promise,await 会把该值转换为已正常处理的Promise,然后等待其处理结果。

-
async function f2() {
+
async function f2() {
   var y = await 20;
   console.log(y); // 20
 }
@@ -65,7 +65,7 @@ f2();
 
 

如果 Promise 处理异常,则异常值被抛出。

-
async function f3() {
+
async function f3() {
   try {
     var z = await Promise.reject(30);
   } catch (e) {
diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_and/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_and/index.html
index 9010ddf09b..c857ac2b41 100644
--- a/files/zh-cn/web/javascript/reference/operators/bitwise_and/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/bitwise_and/index.html
@@ -14,14 +14,14 @@ original_slug: Web/JavaScript/Reference/Operators/按位与
 
 

语法

-
a & b
+
a & b
 

描述

操作数被转换为32位整数,并由一系列位(0和1)表示。 超过32位的数字将丢弃其最高有效位。 例如,以下大于32位的整数将被转换为32位整数:

-
Before: 11100110111110100000000000000110000000000001
+
Before: 11100110111110100000000000000110000000000001
 After:              10100000000000000110000000000001

第一个操作数中的每个位都与第二个操作数中的相应位配对:第一位到第一位,第二位到第二位,依此类推。

@@ -62,7 +62,7 @@ After: 10100000000000000110000000000001
-
.    9 (base 10) = 00000000000000000000000000001001 (base 2)
+
.    9 (base 10) = 00000000000000000000000000001001 (base 2)
     14 (base 10) = 00000000000000000000000000001110 (base 2)
                    --------------------------------
 14 & 9 (base 10) = 00000000000000000000000000001000 (base 2) = 8 (base 10)
@@ -74,7 +74,7 @@ After:              10100000000000000110000000000001

使用按位与

-
// 5: 00000000000000000000000000000101
+
// 5: 00000000000000000000000000000101
 // 2: 00000000000000000000000000000010
 5 & 2; // 0
diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_and_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_and_assignment/index.html index 5c92f0196c..05df4461d6 100644 --- a/files/zh-cn/web/javascript/reference/operators/bitwise_and_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/bitwise_and_assignment/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_AND_assignment

语法

-
Operator: x &= y
+
Operator: x &= y
 Meaning:  x  = x & y
 
@@ -27,7 +27,7 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_AND_assignment

按位与赋值运算

-
let a = 5;
+
let a = 5;
 // 5:     00000000000000000000000000000101
 // 2:     00000000000000000000000000000010
 a &= 2; // 0
diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_not/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_not/index.html index ff285826b0..416bb69347 100644 --- a/files/zh-cn/web/javascript/reference/operators/bitwise_not/index.html +++ b/files/zh-cn/web/javascript/reference/operators/bitwise_not/index.html @@ -19,14 +19,14 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_NOT

语法

-
~a
+
~a
 

描述

操作数被转换为32位二进制表示(0和1)。超过32位的数字将丢弃其最高有效位。如下例子中,超过32位的整数转换为32位整数:

-
Before: 11100110111110100000000000000110000000000001
+
Before: 11100110111110100000000000000110000000000001
 After:              10100000000000000110000000000001

第一个操作数中的每个位都与第二个操作数中的相应位配对:第一位到第一位,第二位到第二位,依此类推。

@@ -54,7 +54,7 @@ After: 10100000000000000110000000000001
-
 9 (base 10) = 00000000000000000000000000001001 (base 2)
+
 9 (base 10) = 00000000000000000000000000001001 (base 2)
                --------------------------------
 ~9 (base 10) = 11111111111111111111111111110110 (base 2) = -10 (base 10)
 
@@ -69,7 +69,7 @@ After: 10100000000000000110000000000001

使用按位取反

-
~0;  // -1
+
~0;  // -1
 ~-1; // 0
 ~1;  // -2
 
diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html index dcd9c54de0..245da8fdab 100644 --- a/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html +++ b/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html @@ -13,14 +13,14 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_OR

语法

-
a | b
+
a | b
 

描述

The operands are converted to 32-bit integers and expressed by a series of bits (zeroes and ones). Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32 bit integer:

-
Before: 11100110111110100000000000000110000000000001
+
Before: 11100110111110100000000000000110000000000001
 After:              10100000000000000110000000000001

Each bit in the first operand is paired with the corresponding bit in the second operand: first bit to first bit, second bit to second bit, and so on.

@@ -61,7 +61,7 @@ After: 10100000000000000110000000000001
-
.    9 (base 10) = 00000000000000000000000000001001 (base 2)
+
.    9 (base 10) = 00000000000000000000000000001001 (base 2)
     14 (base 10) = 00000000000000000000000000001110 (base 2)
                    --------------------------------
 14 | 9 (base 10) = 00000000000000000000000000001111 (base 2) = 15 (base 10)
@@ -73,7 +73,7 @@ After:              10100000000000000110000000000001

Using bitwise OR

-
// 9  (00000000000000000000000000001001)
+
// 9  (00000000000000000000000000001001)
 // 14 (00000000000000000000000000001110)
 
 14 | 9;
diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_or_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_or_assignment/index.html
index 752a80154a..fad4f94082 100644
--- a/files/zh-cn/web/javascript/reference/operators/bitwise_or_assignment/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/bitwise_or_assignment/index.html
@@ -13,14 +13,14 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_OR_assignment
 
 

语法

-
Operator: x |= y
+
Operator: x |= y
 Meaning:  x  = x | y

Examples

Using bitwise OR assignment

-
let a = 5;
+
let a = 5;
 a |= 2; // 7
 // 5: 00000000000000000000000000000101
 // 2: 00000000000000000000000000000010
diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_xor/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_xor/index.html
index c2fa597627..e68e1d436b 100644
--- a/files/zh-cn/web/javascript/reference/operators/bitwise_xor/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/bitwise_xor/index.html
@@ -13,14 +13,14 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_XOR
 
 

语法

-
a ^ b
+
a ^ b
 

描述

The operands are converted to 32-bit integers and expressed by a series of bits (zeroes and ones). Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32 bit integer:

-
Before: 11100110111110100000000000000110000000000001
+
Before: 11100110111110100000000000000110000000000001
 After:              10100000000000000110000000000001

Each bit in the first operand is paired with the corresponding bit in the second operand: first bit to first bit, second bit to second bit, and so on.

@@ -61,7 +61,7 @@ After: 10100000000000000110000000000001
-
.    9 (base 10) = 00000000000000000000000000001001 (base 2)
+
.    9 (base 10) = 00000000000000000000000000001001 (base 2)
     14 (base 10) = 00000000000000000000000000001110 (base 2)
                    --------------------------------
 14 ^ 9 (base 10) = 00000000000000000000000000000111 (base 2) = 7 (base 10)
@@ -73,7 +73,7 @@ After:              10100000000000000110000000000001

Using bitwise XOR

-
// 9  (00000000000000000000000000001001)
+
// 9  (00000000000000000000000000001001)
 // 14 (00000000000000000000000000001110)
 
 14 ^ 9;
diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_xor_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_xor_assignment/index.html
index 7257e9cdb5..d8601d9eba 100644
--- a/files/zh-cn/web/javascript/reference/operators/bitwise_xor_assignment/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/bitwise_xor_assignment/index.html
@@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_XOR_assignment
 
 

语法

-
Operator: x ^= y
+
Operator: x ^= y
 Meaning:  x  = x ^ y

例子

使用按位异或赋值

-
let a = 5;      // 00000000000000000000000000000101
+
let a = 5;      // 00000000000000000000000000000101
 a ^= 3;         // 00000000000000000000000000000011
 
 console.log(a); // 00000000000000000000000000000110
diff --git a/files/zh-cn/web/javascript/reference/operators/decrement/index.html b/files/zh-cn/web/javascript/reference/operators/decrement/index.html
index aca67c15f9..8103a647d1 100644
--- a/files/zh-cn/web/javascript/reference/operators/decrement/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/decrement/index.html
@@ -22,7 +22,7 @@ original_slug: Web/JavaScript/Reference/Operators/自减
 


语法

-
操作符: x-- or --x
+
操作符: x-- or --x
 

语法细节

@@ -35,7 +35,7 @@ original_slug: Web/JavaScript/Reference/Operators/自减

后缀式

-
let x = 3;
+
let x = 3;
 y = x--;
 
 // y = 3
@@ -44,7 +44,7 @@ y = x--;
 
 

前缀式

-
let a = 2;
+
let a = 2;
 b = --a;
 
 // a = 1
diff --git a/files/zh-cn/web/javascript/reference/operators/delete/index.html b/files/zh-cn/web/javascript/reference/operators/delete/index.html
index f460f0e268..ce9d2120a4 100644
--- a/files/zh-cn/web/javascript/reference/operators/delete/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/delete/index.html
@@ -20,12 +20,12 @@ translation_of: Web/JavaScript/Reference/Operators/delete
 
 

语法

-
delete expression
+
delete expression
 

 expression 的计算结果应该是某个属性的引用,例如:

-
delete object.property
+
delete object.property
 delete object['property']
 
@@ -72,7 +72,7 @@ delete object['property']

下面的代码块给出了一个简单的例子:

-
var Employee = {
+
var Employee = {
   age: 28,
   name: 'abc',
   designation: 'developer'
@@ -89,14 +89,14 @@ console.log(delete Employee.salary); // returns true

当一个属性被设置为不可设置,delete操作将不会有任何效果,并且会返回false。在严格模式下会抛出语法错误({{jsxref("SyntaxError")}})。

-
var Employee = {};
+
var Employee = {};
 Object.defineProperty(Employee, 'name', {configurable: false});
 
 console.log(delete Employee.name);  // returns false

{{jsxref("Statements/var","var")}}, {{jsxref("Statements/let","let")}}以及{{jsxref("Statements/const","const")}}创建的不可设置的属性不能被delete操作删除。

-
var nameOther = 'XYZ';
+
var nameOther = 'XYZ';
 
 // 通过以下方法获取全局属性:
 Object.getOwnPropertyDescriptor(window, 'nameOther');
@@ -116,7 +116,7 @@ delete nameOther;   // return false

在严格模式下,如果对一个变量的直接引用、函数的参数或者函数名使用delete操作,将会抛出语法错误({{jsxref("SyntaxError")}})。因此,为避免严格模式下的语法错误,必须以delete object.propertydelete object['property']的形式使用delete运算符。

-
Object.defineProperty(globalThis, 'variable1', { value: 10, configurable: true, });
+
Object.defineProperty(globalThis, 'variable1', { value: 10, configurable: true, });
 Object.defineProperty(globalThis, 'variable2', { value: 10, configurable: false, });
 
 console.log(delete variable1); // true
@@ -125,7 +125,7 @@ console.log(delete variable1); // true
 console.log(delete variable2); // false
 
-
function func(param) {
+
function func(param) {
   // SyntaxError in strict mode.
   console.log(delete param); // false
 }
@@ -140,7 +140,7 @@ console.log(delete func); // false
 
 

任何使用var声明的变量都会被标记为不可设置的。在下面的例子中,salary是不可设置的以及不能被删除的。在非严格模式下,下面的delete操作将会返回false。

-
function Employee() {
+
function Employee() {
   delete salary;
   var salary;
 }
@@ -149,7 +149,7 @@ Employee();

让我们来看看相同的代码在严格模式下会有怎样的表现。会抛出一个语法错误( SyntaxError)而不是返回false。

-
"use strict";
+
"use strict";
 
 function Employee() {
   delete salary;  // SyntaxError
@@ -167,7 +167,7 @@ delete DemoFunction; // SyntaxError

示例

-
// 在全局作用域创建 adminName 属性
+
// 在全局作用域创建 adminName 属性
 adminName = 'xyz';
 
 // 在全局作用域创建 empCount 属性
@@ -213,7 +213,7 @@ function f() {
 
 

在下面的示例中,我们删除一个对象的自己的属性,而原型链上具有相同名称的属性可用:

-
function Foo() {
+
function Foo() {
   this.bar = 10;
 }
 
@@ -240,7 +240,7 @@ console.log(foo.bar);    //undefined
 
 

当用 delete 操作符删除一个数组元素时,被删除的元素已经不再属于该数组。下面的例子中用 delete 删除了 trees[3]

-
var trees = ["redwood","bay","cedar","oak","maple"];
+
var trees = ["redwood","bay","cedar","oak","maple"];
 delete trees[3];
 if (3 in trees) {
    // 这里不会执行
@@ -249,7 +249,7 @@ if (3 in trees) {
 
 

如果你想让一个数组元素继续存在但是其值是 undefined,那么可以使用将 undefined 赋值给这个元素而不是使用 delete。下面的例子中,trees[3] 被赋值为 undefined,但该元素仍然存在。

-
var trees = ["redwood","bay","cedar","oak","maple"];
+
var trees = ["redwood","bay","cedar","oak","maple"];
 trees[3] = undefined;
 if (3 in trees) {
    // 这里会被执行
@@ -257,7 +257,7 @@ if (3 in trees) {
 
 

如果你想通过改变数组的内容来移除一个数组元素,请使用{{jsxref("Array.splice()", "splice()")}} 方法。在下面的例子中,通过使用{{jsxref("Array.splice()", "splice()")}},将trees[3]从数组中移除。

-
var trees = ['redwood', 'bay', 'cedar', 'oak', 'maple'];
+
var trees = ['redwood', 'bay', 'cedar', 'oak', 'maple'];
 trees.splice(3,1);
 console.log(trees); // ["redwood", "bay", "cedar", "maple"]
 
diff --git a/files/zh-cn/web/javascript/reference/operators/division/index.html b/files/zh-cn/web/javascript/reference/operators/division/index.html index 8bfc53db1f..d1af1e83a0 100644 --- a/files/zh-cn/web/javascript/reference/operators/division/index.html +++ b/files/zh-cn/web/javascript/reference/operators/division/index.html @@ -20,14 +20,14 @@ translation_of: Web/JavaScript/Reference/Operators/Division

语法

-
Operator: x / y
+
Operator: x / y
 

例子

基本除法

-
1 / 2              // 0.5
+
1 / 2              // 0.5
 
 Math.floor(3 / 2) // 1
 
@@ -36,7 +36,7 @@ Math.floor(3 / 2) // 1
 
 

除以0

-
2.0 / 0     // Infinity
+
2.0 / 0     // Infinity
 
 2.0 / 0.0   // Infinity, because 0.0 === 0
 
diff --git a/files/zh-cn/web/javascript/reference/operators/division_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/division_assignment/index.html
index a5afd52f49..a9d3508d00 100644
--- a/files/zh-cn/web/javascript/reference/operators/division_assignment/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/division_assignment/index.html
@@ -13,14 +13,14 @@ translation_of: Web/JavaScript/Reference/Operators/Division_assignment
 
 

语法

-
Operator: x /= y
+
Operator: x /= y
 Meaning:  x  = x / y

Examples

Using division assignment

-
// Assuming the following variable
+
// Assuming the following variable
 //  bar = 5
 
 bar /= 2     // 2.5
diff --git a/files/zh-cn/web/javascript/reference/operators/equality/index.html b/files/zh-cn/web/javascript/reference/operators/equality/index.html
index fadd413b17..5ea543e057 100644
--- a/files/zh-cn/web/javascript/reference/operators/equality/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/equality/index.html
@@ -15,7 +15,7 @@ original_slug: Web/JavaScript/Reference/Operators/相等
 
 

语法

-
x == y
+
x == y
 

描述

@@ -52,12 +52,12 @@ original_slug: Web/JavaScript/Reference/Operators/相等

没有类型转换的比较

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

与类型转换比较

-
"1" ==  1;            // true
+
"1" ==  1;            // true
 1 == "1";             // true
 0 == false;           // true
 0 == null;            // false
@@ -71,7 +71,7 @@ number1 == number2;   // false

对象比较

-
const object1 = {"key": "value"}
+
const object1 = {"key": "value"}
 const object2 = {"key": "value"};
 
 object1 == object2 // false
@@ -81,7 +81,7 @@ object2 == object2 // true

请注意,使用构造的字符串new String()是对象。如果将其中之一与字符串文字进行比较,则该String对象将被转换为字符串文字并对其内容进行比较。但是,如果两个操作数都是String对象,则将它们作为对象进行比较,并且必须引用相同的对象才能进行比较:

-
const string1 = "hello";
+
const string1 = "hello";
 const string2 = String("hello");
 const string3 = new String("hello");
 const string4 = new String("hello");
@@ -94,7 +94,7 @@ console.log(string4 == string4); // true

比较日期和字符串

-
const d = new Date('December 17, 1995 03:24:00');
+
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
diff --git a/files/zh-cn/web/javascript/reference/operators/exponentiation/index.html b/files/zh-cn/web/javascript/reference/operators/exponentiation/index.html index 26fbf9ff64..7e138abfa2 100644 --- a/files/zh-cn/web/javascript/reference/operators/exponentiation/index.html +++ b/files/zh-cn/web/javascript/reference/operators/exponentiation/index.html @@ -18,7 +18,7 @@ translation_of: Web/JavaScript/Reference/Operators/Exponentiation

语法

-
Operator: var1 ** var2
+
Operator: var1 ** var2
 

简介

@@ -29,7 +29,7 @@ translation_of: Web/JavaScript/Reference/Operators/Exponentiation

在JavaScript里,你不可能写出一个不明确的求幂表达式。这就是说,你不能立刻将一个一元运算符(+/-/~/!/delete/void/typeof)放在基数前,这样做只会导致一个语法错误。

-
-2 ** 2;
+
-2 ** 2;
 // 4 in Bash, -4 in other languages.
 // This is invalid in JavaScript, as the operation is ambiguous.
 
@@ -44,7 +44,7 @@ translation_of: Web/JavaScript/Reference/Operators/Exponentiation
 
 

基本求幂

-
2 ** 3   // 8
+
2 ** 3   // 8
 3 ** 2   // 9
 3 ** 2.5 // 15.588457268119896
 10 ** -1 // 0.1
@@ -53,7 +53,7 @@ NaN ** 2 // NaN
 
 

结合

-
2 ** 3 ** 2   // 512
+
2 ** 3 ** 2   // 512
 2 ** (3 ** 2) // 512
 (2 ** 3) ** 2 // 64
@@ -61,12 +61,12 @@ NaN ** 2 // NaN

取求幂表达式的值的相反数:

-
-(2 ** 2) // -4
+
-(2 ** 2) // -4
 

将求幂表达式的底数转化为一个负数:

-
(-2) ** 2 // 4
+
(-2) ** 2 // 4
 

规范

diff --git a/files/zh-cn/web/javascript/reference/operators/exponentiation_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/exponentiation_assignment/index.html index f9f53ca532..bd8e58da23 100644 --- a/files/zh-cn/web/javascript/reference/operators/exponentiation_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/exponentiation_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Exponentiation_assignment

语法

-
Operator: x **= y
+
Operator: x **= y
 Meaning:  x  = x ** y

Examples

Using exponentiation assignment

-
// Assuming the following variable
+
// Assuming the following variable
 //  bar = 5
 
 bar **= 2     // 25
diff --git a/files/zh-cn/web/javascript/reference/operators/greater_than/index.html b/files/zh-cn/web/javascript/reference/operators/greater_than/index.html
index afb4a2d134..0c8c8a8328 100644
--- a/files/zh-cn/web/javascript/reference/operators/greater_than/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/greater_than/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Greater_than
 
 

语法

-
x > y
+
x > y

描述

@@ -23,13 +23,13 @@ translation_of: Web/JavaScript/Reference/Operators/Greater_than

字符串的比较

-
console.log("a" > "b");        // false
+
console.log("a" > "b");        // false
 console.log("a" > "a");        // false
 console.log("a" > "3");        // true

字符串和数字的比较

-
console.log("5" > 3);          // true
+
console.log("5" > 3);          // true
 console.log("3" > 3);          // false
 console.log("3" > 5);          // false
 
@@ -41,18 +41,18 @@ console.log("3" > 5n);         // false

数字间的比较

-
console.log(5 > 3);            // true
+
console.log(5 > 3);            // true
 console.log(3 > 3);            // false
 console.log(3 > 5);            // false

数字和 BigInt 数据的比较

-
console.log(5n > 3);           // true
+
console.log(5n > 3);           // true
 console.log(3 > 5n);           // false

Boolean, null, undefined, NaN的比较

-
console.log(true > false);     // true
+
console.log(true > false);     // true
 console.log(false > true);     // false
 
 console.log(true > 0);         // true
diff --git a/files/zh-cn/web/javascript/reference/operators/greater_than_or_equal/index.html b/files/zh-cn/web/javascript/reference/operators/greater_than_or_equal/index.html
index 9fa5b48436..f54a1061fa 100644
--- a/files/zh-cn/web/javascript/reference/operators/greater_than_or_equal/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/greater_than_or_equal/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Greater_than_or_equal
 
 

Syntax

-
 x >= y
+
 x >= y

Description

@@ -23,14 +23,14 @@ translation_of: Web/JavaScript/Reference/Operators/Greater_than_or_equal

String to string comparison

-
console.log("a" >= "b");     // false
+
console.log("a" >= "b");     // false
 console.log("a" >= "a");     // true
 console.log("a" >= "3");     // true
 

String to number comparison

-
console.log("5" >= 3);       // true
+
console.log("5" >= 3);       // true
 console.log("3" >= 3);       // true
 console.log("3" >= 5);       // false
 
@@ -39,19 +39,19 @@ console.log(5 >= "hello");   // false

Number to Number comparison

-
console.log(5 >= 3);         // true
+
console.log(5 >= 3);         // true
 console.log(3 >= 3);         // true
 console.log(3 >= 5);         // false

Number to BigInt comparison

-
console.log(5n >= 3);        // true
+
console.log(5n >= 3);        // true
 console.log(3 >= 3n);        // true
 console.log(3 >= 5n);        // false

Comparing Boolean, null, undefined, NaN

-
console.log(true >= false);  // true
+
console.log(true >= false);  // true
 console.log(true >= true);   // true
 console.log(false >= true);  // false
 
diff --git a/files/zh-cn/web/javascript/reference/operators/in/index.html b/files/zh-cn/web/javascript/reference/operators/in/index.html
index 2ac7bb0ed4..f974698598 100644
--- a/files/zh-cn/web/javascript/reference/operators/in/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/in/index.html
@@ -17,7 +17,7 @@ translation_of: Web/JavaScript/Reference/Operators/in
 
 

语法

-
prop in object
+
prop in object

参数

@@ -35,7 +35,7 @@ translation_of: Web/JavaScript/Reference/Operators/in

下面的例子演示了一些 in 运算符的用法。

-
// 数组
+
// 数组
 var trees = new Array("redwood", "bay", "cedar", "oak", "maple");
 0 in trees        // 返回true
 3 in trees        // 返回true
@@ -58,7 +58,7 @@ var mycar = {make: "Honda", model: "Accord", year: 1998};
 
 

in右操作数必须是一个对象值。例如,你可以指定使用String构造函数创建的字符串,但不能指定字符串文字。

-
var color1 = new String("green");
+
var color1 = new String("green");
 "length" in color1 // 返回true
 var color2 = "coral";
 "length" in color2 // 报错(color2不是对象)
@@ -68,7 +68,7 @@ var color2 = "coral";
 
 

如果你使用 delete 运算符删除了一个属性,则 in 运算符对所删除属性返回 false

-
var mycar = {make: "Honda", model: "Accord", year: 1998};
+
var mycar = {make: "Honda", model: "Accord", year: 1998};
 delete mycar.make;
 "make" in mycar;  // 返回false
 
@@ -79,12 +79,12 @@ delete trees[3];
 
 

如果你只是将一个属性的值赋值为{{jsxref("Global_Objects/undefined", "undefined")}},而没有删除它,则 in 运算仍然会返回true

-
var mycar = {make: "Honda", model: "Accord", year: 1998};
+
var mycar = {make: "Honda", model: "Accord", year: 1998};
 mycar.make = undefined;
 "make" in mycar;  // 返回true
 
-
var trees = new Array("redwood", "bay", "cedar", "oak", "maple");
+
var trees = new Array("redwood", "bay", "cedar", "oak", "maple");
 trees[3] = undefined;
 3 in trees; // 返回true
 
@@ -93,7 +93,7 @@ trees[3] = undefined;

如果一个属性是从原型链上继承来的,in 运算符也会返回 true

-
"toString" in {}; // 返回true
+
"toString" in {}; // 返回true
 

规范

diff --git a/files/zh-cn/web/javascript/reference/operators/increment/index.html b/files/zh-cn/web/javascript/reference/operators/increment/index.html index afe307f389..31620cb751 100644 --- a/files/zh-cn/web/javascript/reference/operators/increment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/increment/index.html @@ -17,7 +17,7 @@ translation_of: Web/JavaScript/Reference/Operators/Increment

语法

-
Operator: x++ or ++x
+
Operator: x++ or ++x
 

描述

@@ -30,7 +30,7 @@ translation_of: Web/JavaScript/Reference/Operators/Increment

后置自增(Postfix increment)

-
let x = 3;
+
let x = 3;
 y = x++;
 
 // y = 3
@@ -39,7 +39,7 @@ y = x++;
 
 

前置自增(Prefix increment)

-
let a = 2;
+
let a = 2;
 b = ++a;
 
 // a = 3
diff --git a/files/zh-cn/web/javascript/reference/operators/inequality/index.html b/files/zh-cn/web/javascript/reference/operators/inequality/index.html
index 11b16d1c2e..cbc90433e7 100644
--- a/files/zh-cn/web/javascript/reference/operators/inequality/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/inequality/index.html
@@ -18,13 +18,13 @@ translation_of: Web/JavaScript/Reference/Operators/Inequality
 
 

语法

-
x != y
+
x != y

描述

不等式运算符检查其操作数是否不相等。这是等于运算符的取反,因此以下两行将始终给出相同的结果: 

-
x != y
+
x != y
 
 !(x == y)
@@ -32,17 +32,17 @@ translation_of: Web/JavaScript/Reference/Operators/Inequality

与等于运算符一样,不等于运算符将尝试转换和比较不同类型的操作数:

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

为避免这种情况,并要求将不同类型视为不同,请使用严格的不等于运算符:

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

例子

没有类型转换的比较

-
1 != 2;              // true
+
1 != 2;              // true
 "hello" != "hola";   // true
 
 1 != 1;              // false
@@ -50,7 +50,7 @@ translation_of: Web/JavaScript/Reference/Operators/Inequality
 
 

与类型转换比较

-
"1" !=  1;            // false
+
"1" !=  1;            // false
 1 != "1";             // false
 0 != false;           // false
 0 != null;            // true
@@ -66,7 +66,7 @@ number1 != number2;   // true

对象比较

-
const object1 = {"key": "value"}
+
const object1 = {"key": "value"}
 const object2 = {"key": "value"};
 
 object1 != object2 // true
diff --git a/files/zh-cn/web/javascript/reference/operators/instanceof/index.html b/files/zh-cn/web/javascript/reference/operators/instanceof/index.html
index a1e3c5a538..9bc5622462 100644
--- a/files/zh-cn/web/javascript/reference/operators/instanceof/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/instanceof/index.html
@@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Operators/instanceof
 
 

语法

-
object instanceof constructor
+
object instanceof constructor

参数

@@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Operators/instanceof

instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上。

-
// 定义构造函数
+
// 定义构造函数
 function C(){}
 function D(){}
 
@@ -87,7 +87,7 @@ o3 instanceof C; // true 因为 C.prototype 现在在 o3 的原型链上
 
 

但是,使用对象文字符号创建的对象在这里是一个例外:虽然原型未定义,但 instanceof Object 返回 true

-
var simpleStr = "This is a simple string";
+
var simpleStr = "This is a simple string";
 var myString  = new String();
 var newStr    = new String("String created with constructor");
 var myDate    = new Date();
@@ -113,7 +113,7 @@ myDate instanceof String;   // 返回 false

下面的代码创建了一个类型 Car,以及该类型的对象实例 mycar. instanceof 运算符表明了这个 mycar 对象既属于 Car 类型,又属于 Object 类型。

-
function Car(make, model, year) {
+
function Car(make, model, year) {
   this.make = make;
   this.model = model;
   this.year = year;
@@ -128,13 +128,13 @@ var b = mycar instanceof Object; // 返回 true
 
 

要检测对象不是某个构造函数的实例时,你可以这样做

-
if (!(mycar instanceof Car)) {
+
if (!(mycar instanceof Car)) {
   // Do something, like mycar = new Car(mycar)
 }

这和以下代码完全不同

-
if (!mycar instanceof Car)
+
if (!mycar instanceof Car)

这段代码永远会得到 false!mycar 将在 instanceof 之前被处理,所以你总是在验证一个布尔值是否是 Car 的一个实例)。

diff --git a/files/zh-cn/web/javascript/reference/operators/left_shift/index.html b/files/zh-cn/web/javascript/reference/operators/left_shift/index.html index 83fe088941..4bae0bcde0 100644 --- a/files/zh-cn/web/javascript/reference/operators/left_shift/index.html +++ b/files/zh-cn/web/javascript/reference/operators/left_shift/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Left_shift

语法

-
a << b
+
a << b
 

描述

@@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Operators/Left_shift

例如, 9 << 2 得出 36:

-
.    9 (十进制): 00000000000000000000000000001001 (二进制)
+
.    9 (十进制): 00000000000000000000000000001001 (二进制)
                   --------------------------------
 9 << 2 (十进制): 00000000000000000000000000100100 (二进制) = 36 (十进制)
 
@@ -34,7 +34,7 @@ translation_of: Web/JavaScript/Reference/Operators/Left_shift

使用左移

-
9 << 3; // 72
+
9 << 3; // 72
 
 // 9 * 2³ = 9 * 8 = 72
 
diff --git a/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.html index ccf5bbce00..e48b9616d0 100644 --- a/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Left_shift_assignment

语法

-
Operator: x <<= y
+
Operator: x <<= y
 Meaning:  x   = x << y

Examples

Using left shift assignment

-
let a = 5;
+
let a = 5;
 // 00000000000000000000000000000101
 
 a <<= 2; // 20
diff --git a/files/zh-cn/web/javascript/reference/operators/less_than/index.html b/files/zh-cn/web/javascript/reference/operators/less_than/index.html
index 1a33554b98..d98a89f03c 100644
--- a/files/zh-cn/web/javascript/reference/operators/less_than/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/less_than/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Less_than
 
 

语法

-
 x < y
+
 x < y

Description

@@ -38,13 +38,13 @@ translation_of: Web/JavaScript/Reference/Operators/Less_than

String to string comparison

-
console.log("a" < "b");        // true
+
console.log("a" < "b");        // true
 console.log("a" < "a");        // false
 console.log("a" < "3");        // false

String to number comparison

-
console.log("5" < 3);          // false
+
console.log("5" < 3);          // false
 console.log("3" < 3);          // false
 console.log("3" < 5);          // true
 
@@ -56,18 +56,18 @@ console.log("3" < 5n);         // true

Number to Number comparison

-
console.log(5 < 3);            // false
+
console.log(5 < 3);            // false
 console.log(3 < 3);            // false
 console.log(3 < 5);            // true

Number to BigInt comparison

-
console.log(5n < 3);           // false
+
console.log(5n < 3);           // false
 console.log(3 < 5n);           // true

Comparing Boolean, null, undefined, NaN

-
console.log(true < false);     // false
+
console.log(true < false);     // false
 console.log(false < true);     // true
 
 console.log(0 < true);         // true
diff --git a/files/zh-cn/web/javascript/reference/operators/less_than_or_equal/index.html b/files/zh-cn/web/javascript/reference/operators/less_than_or_equal/index.html
index 97a6f6746b..498dc2bbfd 100644
--- a/files/zh-cn/web/javascript/reference/operators/less_than_or_equal/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/less_than_or_equal/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Less_than_or_equal
 
 

Syntax

-
 x <= y
+
 x <= y

Description

@@ -23,14 +23,14 @@ translation_of: Web/JavaScript/Reference/Operators/Less_than_or_equal

String to string comparison

-
console.log("a" <= "b");     // true
+
console.log("a" <= "b");     // true
 console.log("a" <= "a");     // true
 console.log("a" <= "3");     // false
 

String to number comparison

-
console.log("5" <= 3);       // false
+
console.log("5" <= 3);       // false
 console.log("3" <= 3);       // true
 console.log("3" <= 5);       // true
 
@@ -39,19 +39,19 @@ console.log(5 <= "hello");   // false

Number to Number comparison

-
console.log(5 <= 3);         // false
+
console.log(5 <= 3);         // false
 console.log(3 <= 3);         // true
 console.log(3 <= 5);         // true

Number to BigInt comparison

-
console.log(5n <= 3);        // false
+
console.log(5n <= 3);        // false
 console.log(3 <= 3n);        // true
 console.log(3 <= 5n);        // true

Comparing Boolean, null, undefined, NaN

-
console.log(true <= false);  // false
+
console.log(true <= false);  // false
 console.log(true <= true);   // true
 console.log(false <= true);  // true
 
diff --git a/files/zh-cn/web/javascript/reference/operators/logical_and/index.html b/files/zh-cn/web/javascript/reference/operators/logical_and/index.html
index 78c4eee070..e418a76518 100644
--- a/files/zh-cn/web/javascript/reference/operators/logical_and/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/logical_and/index.html
@@ -14,7 +14,7 @@ original_slug: Web/JavaScript/Reference/Operators/逻辑和
 
 

Syntax

-
expr1 && expr2
+
expr1 && expr2
 

Description

@@ -43,7 +43,7 @@ original_slug: Web/JavaScript/Reference/Operators/逻辑和

Short circuit means that the expr part above is not evaluated, hence any side effects of doing so do not take effect (e.g., if expr is a function call, the calling never takes place). This happens because the value of the operator is already determined after the evaluation of the first operand. See example:

-
function A(){ console.log('called A'); return false; }
+
function A(){ console.log('called A'); return false; }
 function B(){ console.log('called B'); return true; }
 
 console.log( A() && B() );
@@ -55,7 +55,7 @@ console.log( A() && B() );
 
 

The following expressions might seem equivalent, but they are not, because the && operator is executed before the || operator (see operator precedence).

-
true || false && false      // returns true, because && is executed first
+
true || false && false      // returns true, because && is executed first
 (true || false) && false    // returns false, because operator precedence cannot apply

Examples

@@ -64,7 +64,7 @@ console.log( A() && B() );

The following code shows examples of the && (logical AND) operator.

-
a1 = true  && true       // t && t returns true
+
a1 = true  && true       // t && t returns true
 a2 = true  && false      // t && f returns false
 a3 = false && true       // f && t returns false
 a4 = false && (3 == 4)   // f && f returns false
@@ -80,21 +80,21 @@ a9 = false && ''         // f && f returns false

The following operation involving booleans:

-
bCondition1 && bCondition2
+
bCondition1 && bCondition2

is always equal to:

-
!(!bCondition1 || !bCondition2)
+
!(!bCondition1 || !bCondition2)

Converting OR to AND

The following operation involving booleans:

-
bCondition1 || bCondition2
+
bCondition1 || bCondition2

is always equal to:

-
!(!bCondition1 && !bCondition2)
+
!(!bCondition1 && !bCondition2)

Removing nested parentheses

@@ -102,11 +102,11 @@ a9 = false && '' // f && f returns false

The following composite operation involving booleans:

-
bCondition1 || (bCondition2 && bCondition3)
+
bCondition1 || (bCondition2 && bCondition3)

is always equal to:

-
bCondition1 || bCondition2 && bCondition3
+
bCondition1 || bCondition2 && bCondition3

Specifications

diff --git a/files/zh-cn/web/javascript/reference/operators/logical_and_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/logical_and_assignment/index.html index 3ed9a1582a..4ee00585a5 100644 --- a/files/zh-cn/web/javascript/reference/operators/logical_and_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/logical_and_assignment/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_AND_assignment

语法

-
expr1 &&= expr2
+
expr1 &&= expr2
 

描述

@@ -28,18 +28,18 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_AND_assignment

Logical AND assignment short-circuits as well meaning that x &&= y is equivalent to:

-
x && (x = y);
+
x && (x = y);

And not equivalent to the following which would always perform an assignment:

-
x = x && y;
+
x = x && y;
 

例子

Using logical AND assignment

-
let x = 0;
+
let x = 0;
 let y = 1;
 
 x &&= 0; // 0
diff --git a/files/zh-cn/web/javascript/reference/operators/logical_not/index.html b/files/zh-cn/web/javascript/reference/operators/logical_not/index.html
index f05bfb180a..e27ad4db4f 100644
--- a/files/zh-cn/web/javascript/reference/operators/logical_not/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/logical_not/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_NOT
 
 

语法

-
!expr
+
!expr
 

Description

@@ -40,7 +40,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_NOT

The following code shows examples of the ! (logical NOT) operator.

-
n1 = !true               // !t returns false
+
n1 = !true               // !t returns false
 n2 = !false              // !f returns true
 n3 = !''                 // !f returns true
 n4 = !'Cat'              // !t returns false
@@ -51,7 +51,7 @@ n4 = !'Cat' // !t returns false

The same conversion can be done through the {{jsxref("Global_Objects/Boolean/Boolean", "Boolean")}} function.

-
n1 = !!true                   // !!truthy returns true
+
n1 = !!true                   // !!truthy returns true
 n2 = !!{}                     // !!truthy returns true: any object is truthy...
 n3 = !!(new Boolean(false))   // ...even Boolean objects with a false .valueOf()!
 n4 = !!false                  // !!falsy returns false
@@ -62,11 +62,11 @@ n6 = !!Boolean(false)         // !!falsy returns false

The following operation involving booleans:

-
!!bCondition
+
!!bCondition

is always equal to:

-
bCondition
+
bCondition

Specifications

diff --git a/files/zh-cn/web/javascript/reference/operators/logical_nullish_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/logical_nullish_assignment/index.html index a57c18e5c2..c4fea43591 100644 --- a/files/zh-cn/web/javascript/reference/operators/logical_nullish_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/logical_nullish_assignment/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_nullish_assignment

语法

-
expr1 ??= expr2
+
expr1 ??= expr2
 

描述

@@ -28,18 +28,18 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_nullish_assignment

逻辑空赋值的语法短路也意味着 x ??= y 等价于:

-
x ?? (x = y);
+
x ?? (x = y);

而不等价于如下的表达式,因为其一定会发生赋值:

-
x = x ?? y;
+
x = x ?? y;
 

例子

使用逻辑空赋值

-
function config(options) {
+
function config(options) {
   options.duration ??= 100;
   options.speed ??= 25;
   return options;
diff --git a/files/zh-cn/web/javascript/reference/operators/logical_or/index.html b/files/zh-cn/web/javascript/reference/operators/logical_or/index.html
index 1a8f881377..3604b99140 100644
--- a/files/zh-cn/web/javascript/reference/operators/logical_or/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/logical_or/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_OR
 
 

语法

-
expr1 || expr2
+
expr1 || expr2
 

Description

@@ -42,7 +42,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_OR

Short circuit means that the expr part above is not evaluated, hence any side effects of doing so do not take effect (e.g., if expr is a function call, the calling never takes place). This happens because the value of the operator is already determined after the evaluation of the first operand. See example:

-
function A(){ console.log('called A'); return false; }
+
function A(){ console.log('called A'); return false; }
 function B(){ console.log('called B'); return true; }
 
 console.log( B() || A() );
@@ -54,7 +54,7 @@ console.log( B() || A() );
 
 

The following expressions might seem equivalent, but they are not, because the && operator is executed before the || operator (see operator precedence).

-
true || false && false      // returns true, because && is executed first
+
true || false && false      // returns true, because && is executed first
 (true || false) && false    // returns false, because operator precedence cannot apply

Examples

@@ -63,7 +63,7 @@ console.log( B() || A() );

The following code shows examples of the || (logical OR) operator.

-
o1 = true  || true       // t || t returns true
+
o1 = true  || true       // t || t returns true
 o2 = false || true       // f || t returns true
 o3 = true  || false      // t || f returns true
 o4 = false || (3 == 4)   // f || f returns false
@@ -85,21 +85,21 @@ o10 = false || varObject // f || object returns varObject
 
 

The following operation involving booleans:

-
bCondition1 && bCondition2
+
bCondition1 && bCondition2

is always equal to:

-
!(!bCondition1 || !bCondition2)
+
!(!bCondition1 || !bCondition2)

Converting OR to AND

The following operation involving booleans:

-
bCondition1 || bCondition2
+
bCondition1 || bCondition2

is always equal to:

-
!(!bCondition1 && !bCondition2)
+
!(!bCondition1 && !bCondition2)

Removing nested parentheses

@@ -107,11 +107,11 @@ o10 = false || varObject // f || object returns varObject

The following composite operation involving booleans:

-
bCondition1 && (bCondition2 || bCondition3)
+
bCondition1 && (bCondition2 || bCondition3)

is always equal to:

-
!(!bCondition1 || !bCondition2 && !bCondition3)
+
!(!bCondition1 || !bCondition2 && !bCondition3)

Specifications

diff --git a/files/zh-cn/web/javascript/reference/operators/multiplication/index.html b/files/zh-cn/web/javascript/reference/operators/multiplication/index.html index db346f4cbe..a37d1e7a54 100644 --- a/files/zh-cn/web/javascript/reference/operators/multiplication/index.html +++ b/files/zh-cn/web/javascript/reference/operators/multiplication/index.html @@ -15,25 +15,25 @@ translation_of: Web/JavaScript/Reference/Operators/Multiplication

语法

-
Operator: x * y
+
Operator: x * y
 

例子

使用数字相乘

-
 2 * 2      // 4
+
 2 * 2      // 4
 -2 * 2     // -4
 

使用 Infinity 相乘

-
Infinity * 0         // NaN
+
Infinity * 0         // NaN
 Infinity * Infinity  // Infinity

使用非数字相乘

-
'foo' * 2 // NaN
+
'foo' * 2 // NaN

规范

diff --git a/files/zh-cn/web/javascript/reference/operators/multiplication_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/multiplication_assignment/index.html index e05019acba..274729034b 100644 --- a/files/zh-cn/web/javascript/reference/operators/multiplication_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/multiplication_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Multiplication_assignment

语法

-
Operator: x *= y
+
Operator: x *= y
 Meaning:  x  = x * y

Examples

Using multiplication assignment

-
// Assuming the following variable
+
// Assuming the following variable
 //  bar = 5
 
 bar *= 2     // 10
diff --git a/files/zh-cn/web/javascript/reference/operators/new/index.html b/files/zh-cn/web/javascript/reference/operators/new/index.html
index 0b2d5c24c7..e6833d4cc7 100644
--- a/files/zh-cn/web/javascript/reference/operators/new/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/new/index.html
@@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Operators/new
 
 

语法

-
new constructor[([arguments])]
+
new constructor[([arguments])]

参数

@@ -67,7 +67,7 @@ translation_of: Web/JavaScript/Reference/Operators/new

你可以使用 Function.prototype 属性将共享属性添加到以前定义的对象类型。这定义了一个由该函数创建的所有对象共享的属性,而不仅仅是对象类型的其中一个实例。下面的代码将一个值为 nullcolor 属性添加到 car 类型的所有对象,然后仅在实例对象 car1 中用字符串 "black" 覆盖该值。详见 prototype

-
function Car() {}
+
function Car() {}
 car1 = new Car();
 car2 = new Car();
 
@@ -95,7 +95,7 @@ console.log(car2.color) // original color
 
 

假设你要创建一个汽车的对象类型。你希望这个类型叫做car,这个类型具备make, model, year等属性,要做到这些,你需要写这样一个函数:

-
function Car(make, model, year) {
+
function Car(make, model, year) {
    this.make = make;
    this.model = model;
    this.year = year;
@@ -104,19 +104,19 @@ console.log(car2.color) // original color
 
 

现在,你可以如下所示创建一个 mycar 的对象:

-
var mycar = new Car("Eagle", "Talon TSi", 1993);
+
var mycar = new Car("Eagle", "Talon TSi", 1993);

这段代码创建了 mycar 并给他的属性指定值,于是 mycar.make 的值为"Eagle", mycar.year 的值为1993,以此类推。

你可以通过调用 new 来创建任意个汽车对象。例如:

-
var kenscar = new Car("Nissan", "300ZX", 1992);
+
var kenscar = new Car("Nissan", "300ZX", 1992);

对象属性为其他对象

假设你定义了一个对象叫做 person

-
function Person(name, age, sex) {
+
function Person(name, age, sex) {
    this.name = name;
    this.age = age;
    this.sex = sex;
@@ -125,13 +125,13 @@ console.log(car2.color) // original color
 
 

然后实例化两个新的 person 对象如下:

-
var rand = new Person("Rand McNally", 33, "M");
+
var rand = new Person("Rand McNally", 33, "M");
 var ken = new Person("Ken Jones", 39, "M");
 

然后你可以重写 car 的定义,添加一个值为 person 对象的 owner 属性,如下:

-
function Car(make, model, year, owner) {
+
function Car(make, model, year, owner) {
    this.make = make;
    this.model = model;
    this.year = year;
@@ -141,13 +141,13 @@ var ken = new Person("Ken Jones", 39, "M");
 
 

为了实例化新的对象,你可以用如下代码:

-
var car1 = new Car("Eagle", "Talon TSi", 1993, rand);
+
var car1 = new Car("Eagle", "Talon TSi", 1993, rand);
 var car2 = new Car("Nissan", "300ZX", 1992, ken);
 

创建对象时,并没有传字符串或数字给owner,而是传了对象 randken 。这个时候,你可以这样来获取 car2 的owner的name:

-
car2.owner.name
+
car2.owner.name

规范

diff --git a/files/zh-cn/web/javascript/reference/operators/nullish_coalescing_operator/index.html b/files/zh-cn/web/javascript/reference/operators/nullish_coalescing_operator/index.html index 59b7443e60..1dfd0302a9 100644 --- a/files/zh-cn/web/javascript/reference/operators/nullish_coalescing_operator/index.html +++ b/files/zh-cn/web/javascript/reference/operators/nullish_coalescing_operator/index.html @@ -23,7 +23,7 @@ translation_of: Web/JavaScript/Reference/Operators/Nullish_coalescing_operator

语法

-
leftExpr ?? rightExpr
+
leftExpr ?? rightExpr
 

示例

@@ -32,7 +32,7 @@ translation_of: Web/JavaScript/Reference/Operators/Nullish_coalescing_operator

在这个例子中,我们使用空值合并操作符为常量提供默认值,保证常量不为 null 或者 undefined

-
const nullValue = null;
+
const nullValue = null;
 const emptyText = ""; // 空字符串,是一个假值,Boolean("") === false
 const someNumber = 42;
 
@@ -48,14 +48,14 @@ console.log(valC); // 42

以前,如果想为一个变量赋默认值,通常的做法是使用逻辑或操作符(||):

-
let foo;
+
let foo;
 
 //  foo is never assigned any value so it is still undefined
 let someDummyText = foo || 'Hello!';

然而,由于 || 是一个布尔逻辑运算符,左侧的操作数会被强制转换成布尔值用于求值。任何假值(0, '', NaN, null, undefined)都不会被返回。这导致如果你使用0''NaN作为有效值,就会出现不可预料的后果。

-
let count = 0;
+
let count = 0;
 let text = "";
 
 let qty = count || 42;
@@ -65,7 +65,7 @@ console.log(message); // "hi!",而不是 ""

空值合并操作符可以避免这种陷阱,其只在第一个操作数为null 或 undefined 时(而不是其它假值)返回第二个操作数:

-
let myText = ''; // An empty string (which is also a falsy value)
+
let myText = ''; // An empty string (which is also a falsy value)
 
 let notFalsyText = myText || 'Hello world';
 console.log(notFalsyText); // Hello world
@@ -78,7 +78,7 @@ console.log(preservingFalsy); // '' (as myText is neither undefined nor null)
 
 

与 OR 和 AND 逻辑操作符相似,当左表达式不为 null 或 undefined 时,不会对右表达式进行求值。

-
function A() { console.log('函数 A 被调用了'); return undefined; }
+
function A() { console.log('函数 A 被调用了'); return undefined; }
 function B() { console.log('函数 B 被调用了'); return false; }
 function C() { console.log('函数 C 被调用了'); return "foo"; }
 
@@ -96,19 +96,19 @@ console.log( B() ?? C() );
 
 

将 ?? 直接与 AND(&&)和 OR(||)操作符组合使用是不可取的。(译者注:应当是因为空值合并操作符和其他逻辑操作符之间的运算优先级/运算顺序是未定义的)这种情况下会抛出 SyntaxError

-
null || undefined ?? "foo"; // 抛出 SyntaxError
+
null || undefined ?? "foo"; // 抛出 SyntaxError
 true || undefined ?? "foo"; // 抛出 SyntaxError

但是,如果使用括号来显式表明运算优先级,是没有问题的:

-
(null || undefined ) ?? "foo"; // 返回 "foo"
+
(null || undefined ) ?? "foo"; // 返回 "foo"
 

与可选链式操作符(?.)的关系

空值合并操作符针对 undefined 与 null 这两个值,可选链式操作符(?. 也是如此。在这访问属性可能为 undefined 与 null 的对象时,可选链式操作符非常有用。

-
let foo = { someFooProp: "hi" };
+
let foo = { someFooProp: "hi" };
 
 console.log(foo.someFooProp?.toUpperCase()); // "HI"
 console.log(foo.someBarProp?.toUpperCase()); // undefined
diff --git a/files/zh-cn/web/javascript/reference/operators/optional_chaining/index.html b/files/zh-cn/web/javascript/reference/operators/optional_chaining/index.html
index 6f639f537a..e765e6d66b 100644
--- a/files/zh-cn/web/javascript/reference/operators/optional_chaining/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/optional_chaining/index.html
@@ -26,7 +26,7 @@ original_slug: Web/JavaScript/Reference/Operators/可选链
 
 

语法

-
obj?.prop
+
obj?.prop
 obj?.[expr]
 arr?.[index]
 func?.(args)
@@ -38,19 +38,19 @@ original_slug: Web/JavaScript/Reference/Operators/可选链
 
 

比如,思考一个存在嵌套结构的对象 obj。不使用可选链的话,查找一个深度嵌套的子属性时,需要验证之间的引用,例如:

-
let nestedProp = obj.first && obj.first.second;
+
let nestedProp = obj.first && obj.first.second;

为了避免报错,在访问obj.first.second之前,要保证 obj.first 的值既不是 null,也不是 undefined。如果只是直接访问 obj.first.second,而不对 obj.first 进行校验,则有可能抛出错误。

有了可选链操作符(?.),在访问 obj.first.second 之前,不再需要明确地校验 obj.first 的状态,再并用短路计算获取最终结果:

-
let nestedProp = obj.first?.second;
+
let nestedProp = obj.first?.second;

通过使用 ?. 操作符取代 . 操作符,JavaScript 会在尝试访问 obj.first.second 之前,先隐式地检查并确定 obj.first 既不是 null 也不是 undefined。如果obj.first null 或者 undefined,表达式将会短路计算直接返回 undefined

这等价于以下表达式,但实际上没有创建临时变量:

-
let temp = obj.first;
+
let temp = obj.first;
 let nestedProp = ((temp === null || temp === undefined) ? undefined : temp.second);

可选链与函数调用

@@ -59,7 +59,7 @@ let nestedProp = ((temp === null || temp === undefined) ? undefined : temp.secon

函数调用时如果被调用的方法不存在,使用可选链可以使表达式自动返回undefined而不是抛出一个异常。

-
let result = someInterface.customMethod?.();
+
let result = someInterface.customMethod?.();

注意: 如果存在一个属性名且不是函数, 使用 ?. 仍然会产生一个 {{JSxRef("TypeError")}} 异常 (x.y is not a function).

@@ -73,7 +73,7 @@ let nestedProp = ((temp === null || temp === undefined) ? undefined : temp.secon

如果使用解构赋值来解构的一个对象的回调函数或 fetch 方法,你可能得到不能当做函数直接调用的不存在的值,除非你已经校验了他们的存在性。使用?.的你可以忽略这些额外的校验:

-
//  ES2019的写法
+
//  ES2019的写法
 function doSomething(onContent, onError) {
   try {
     // ... do something with the data
@@ -86,7 +86,7 @@ function doSomething(onContent, onError) {
 }
 
-
// 使用可选链进行函数调用
+
// 使用可选链进行函数调用
 function doSomething(onContent, onError) {
   try {
    // ... do something with the data
@@ -101,16 +101,16 @@ function doSomething(onContent, onError) {
 
 

当使用方括号与属性名的形式来访问属性时,你也可以使用可选链操作符:

-
let nestedProp = obj?.['prop' + 'Name'];
+
let nestedProp = obj?.['prop' + 'Name'];

可选链不能用于赋值

-
let object = {};
+
let object = {};
 object?.property = 1; // Uncaught SyntaxError: Invalid left-hand side in assignment

可选链访问数组元素

-
let arrayItem = arr?.[42];
+
let arrayItem = arr?.[42];

例子

@@ -118,7 +118,7 @@ object?.property = 1; // Uncaught SyntaxError: Invalid left-hand side in assignm

如下的例子在一个不含 bar 成员的 Map 中查找 bar 成员的 name 属性,因此结果是 undefined

-
let myMap = new Map();
+
let myMap = new Map();
 myMap.set("foo", {name: "baz", desc: "inga"});
 
 let nameBar = myMap.get("bar")?.name;
@@ -127,7 +127,7 @@ let nameBar = myMap.get("bar")?.name;

当在表达式中使用可选链时,如果左操作数是 nullundefined,表达式将不会被计算,例如:

-
let potentiallyNullObj = null;
+
let potentiallyNullObj = null;
 let x = 0;
 let prop = potentiallyNullObj?.[x++];
 
@@ -138,7 +138,7 @@ console.log(x); // x 将不会被递增,依旧输出 0
 
 

可以连续使用可选链读取多层嵌套结构:

-
let customer = {
+
let customer = {
   name: "Carl",
   details: {
     age: 82,
@@ -155,7 +155,7 @@ let duration = vacations.trip?.getTime?.();
 
 

{{JSxRef("Operators/Nullish_Coalescing_Operator", "空值合并操作符")}}可以在使用可选链时设置一个默认值:

-
let customer = {
+
let customer = {
   name: "Carl",
   details: { age: 82 }
 };
diff --git a/files/zh-cn/web/javascript/reference/operators/remainder/index.html b/files/zh-cn/web/javascript/reference/operators/remainder/index.html
index f09292e4ff..a2d1e19fa6 100644
--- a/files/zh-cn/web/javascript/reference/operators/remainder/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/remainder/index.html
@@ -21,14 +21,14 @@ original_slug: Web/JavaScript/Reference/Operators/取余
 
 

语法

-
Operator: var1 % var2
+
Operator: var1 % var2
 

示例

被除数为正数

-
 12 % 5  //  2
+
 12 % 5  //  2
  1 % -2 //  1
  1 % 2  //  1
  2 % 3  //  2
@@ -37,13 +37,13 @@ original_slug: Web/JavaScript/Reference/Operators/取余
 
 

被除数为负数

-
-12 % 5 // -2
+
-12 % 5 // -2
 -1 % 2  // -1
 -4 % 2  // -0

被除数为NaN

-
NaN % 2 // NaN
+
NaN % 2 // NaN

规范

diff --git a/files/zh-cn/web/javascript/reference/operators/remainder_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/remainder_assignment/index.html index a9d015e467..d36fa7cdc3 100644 --- a/files/zh-cn/web/javascript/reference/operators/remainder_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/remainder_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Remainder_assignment

语法

-
Operator: x %= y
+
Operator: x %= y
 Meaning:  x  = x % y

Examples

Using remainder assignment

-
// Assuming the following variable
+
// Assuming the following variable
 //  bar = 5
 
 bar %= 2     // 1
diff --git a/files/zh-cn/web/javascript/reference/operators/right_shift/index.html b/files/zh-cn/web/javascript/reference/operators/right_shift/index.html
index f049a499a9..583da5cafe 100644
--- a/files/zh-cn/web/javascript/reference/operators/right_shift/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/right_shift/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Right_shift
 
 

语法

-
a >> b
+
a >> b
 

Description

@@ -22,14 +22,14 @@ translation_of: Web/JavaScript/Reference/Operators/Right_shift

For example, 9 >> 2 yields 2:

-
.    9 (base 10): 00000000000000000000000000001001 (base 2)
+
.    9 (base 10): 00000000000000000000000000001001 (base 2)
                   --------------------------------
 9 >> 2 (base 10): 00000000000000000000000000000010 (base 2) = 2 (base 10)
 

Likewise, -9 >> 2 yields -3, because the sign is preserved:

-
.    -9 (base 10): 11111111111111111111111111110111 (base 2)
+
.    -9 (base 10): 11111111111111111111111111110111 (base 2)
                    --------------------------------
 -9 >> 2 (base 10): 11111111111111111111111111111101 (base 2) = -3 (base 10)
 
@@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Operators/Right_shift

Using right shift

-
 9 >> 2; //  2
+
 9 >> 2; //  2
 -9 >> 2; // -3
 
diff --git a/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.html index f9e8b3c8c4..0ebfbbd51e 100644 --- a/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Right_shift_assignment

语法

-
Operator: x >>= y
+
Operator: x >>= y
 Meaning:  x   = x >> y

Examples

Using right shift assignment

-
let a = 5; //   (00000000000000000000000000000101)
+
let a = 5; //   (00000000000000000000000000000101)
 a >>= 2;   // 1 (00000000000000000000000000000001)
 
 let b = -5; //  (-00000000000000000000000000000101)
diff --git a/files/zh-cn/web/javascript/reference/operators/spread_syntax/index.html b/files/zh-cn/web/javascript/reference/operators/spread_syntax/index.html
index 0397ee8e96..3f21c5b960 100644
--- a/files/zh-cn/web/javascript/reference/operators/spread_syntax/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/spread_syntax/index.html
@@ -20,15 +20,15 @@ translation_of: Web/JavaScript/Reference/Operators/Spread_syntax
 
 

函数调用:

-
myFunction(...iterableObj);
+
myFunction(...iterableObj);

字面量数组构造或字符串:

-
[...iterableObj, '4', ...'hello', 6];
+
[...iterableObj, '4', ...'hello', 6];

构造字面量对象时,进行克隆或者属性拷贝(ECMAScript 2018规范新增特性):

-
let objClone = { ...obj };
+
let objClone = { ...obj };

示例

@@ -38,19 +38,19 @@ translation_of: Web/JavaScript/Reference/Operators/Spread_syntax

如果想将数组元素迭代为函数参数,一般使用{{jsxref( "Function.prototype.apply")}} 的方式进行调用。

-
function myFunction(x, y, z) { }
+
function myFunction(x, y, z) { }
 var args = [0, 1, 2];
 myFunction.apply(null, args);

有了展开语法,可以这样写:

-
function myFunction(x, y, z) { }
+
function myFunction(x, y, z) { }
 var args = [0, 1, 2];
 myFunction(...args);

所有参数都可以通过展开语法来传值,也不限制多次使用展开语法。

-
function myFunction(v, w, x, y, z) { }
+
function myFunction(v, w, x, y, z) { }
 var args = [0, 1];
 myFunction(-1, ...args, 2, ...[3]);
@@ -58,13 +58,13 @@ myFunction(-1, ...args, 2, ...[3]);

使用 new 关键字来调用构造函数时,不能直接使用数组+ apply 的方式(apply 执行的是调用 [[Call]] , 而不是构造 [[Construct]])。当然, 有了展开语法, 将数组展开为构造函数的参数就很简单了:

-
var dateFields = [1970, 0, 1]; // 1970年1月1日
+
var dateFields = [1970, 0, 1]; // 1970年1月1日
 var d = new Date(...dateFields);
 

如果不使用展开语法, 想将数组元素传给构造函数, 实现方式可能是这样的:

-
function applyAndNew(constructor, args) {
+
function applyAndNew(constructor, args) {
    function partial () {
       return constructor.apply(this, args);
    };
@@ -96,7 +96,7 @@ console.log(new myConstructorWithArguments);
 
 

没有展开语法的时候,只能组合使用 push, splice, concat 等方法,来将已有数组元素变成新数组的一部分。有了展开语法,  通过字面量方式, 构造新数组会变得更简单、更优雅:

-
var parts = ['shoulders', 'knees'];
+
var parts = ['shoulders', 'knees'];
 var lyrics = ['head', ...parts, 'and', 'toes']; 
 // ["head", "shoulders", "knees", "and", "toes"]
 
@@ -105,7 +105,7 @@ var lyrics = ['head', ...parts, 'and', 'toes'];

数组拷贝(copy)

-
var arr = [1, 2, 3];
+
var arr = [1, 2, 3];
 var arr2 = [...arr]; // like arr.slice()
 arr2.push(4);
 
@@ -115,7 +115,7 @@ arr2.push(4);
 
 

提示: 实际上, 展开语法和 {{jsxref("Object.assign()")}} 行为一致, 执行的都是浅拷贝(只遍历一层)。如果想对多维数组进行深拷贝, 下面的示例就有些问题了。

-
var a = [[1], [2], [3]];
+
var a = [[1], [2], [3]];
 var b = [...a];
 b.shift().shift(); // 1
 // Now array a is affected as well: [[2], [3]]
@@ -125,28 +125,28 @@ b.shift().shift(); // 1
 
 

{{jsxref("Array.concat")}} 函数常用于将一个数组连接到另一个数组的后面。如果不使用展开语法, 代码可能是下面这样的:

-
var arr1 = [0, 1, 2];
+
var arr1 = [0, 1, 2];
 var arr2 = [3, 4, 5];
 // 将 arr2 中所有元素附加到 arr1 后面并返回
 var arr3 = arr1.concat(arr2);

使用展开语法:

-
var arr1 = [0, 1, 2];
+
var arr1 = [0, 1, 2];
 var arr2 = [3, 4, 5];
 var arr3 = [...arr1, ...arr2];
 

{{jsxref("Array.unshift")}} 方法常用于在数组的开头插入新元素/数组.  不使用展开语法, 示例如下:

-
var arr1 = [0, 1, 2];
+
var arr1 = [0, 1, 2];
 var arr2 = [3, 4, 5];
 // 将 arr2 中的元素插入到 arr1 的开头
 Array.prototype.unshift.apply(arr1, arr2) // arr1 现在是 [3, 4, 5, 0, 1, 2]

如果使用展开语法, 代码如下:  [请注意, 这里使用展开语法创建了一个新的 arr1 数组,  {{jsxref("Array.unshift")}} 方法则是修改了原本存在的 arr1 数组]:

-
var arr1 = [0, 1, 2];
+
var arr1 = [0, 1, 2];
 var arr2 = [3, 4, 5];
 arr1 = [...arr2, ...arr1]; // arr1 现在为 [3, 4, 5, 0, 1, 2]
 
@@ -157,7 +157,7 @@ arr1 = [...arr2, ...arr1]; // arr1 现在为 [3, 4, 5, 0, 1, 2]

浅拷贝(Shallow-cloning, 不包含 prototype) 和对象合并, 可以使用更简短的展开语法。而不必再使用 {{jsxref("Object.assign()")}} 方式.

-
var obj1 = { foo: 'bar', x: 42 };
+
var obj1 = { foo: 'bar', x: 42 };
 var obj2 = { foo: 'baz', y: 13 };
 
 var clonedObj = { ...obj1 };
@@ -173,7 +173,7 @@ var mergedObj = { ...obj1, ...obj2 };
 
 

提示: 不能替换或者模拟 {{jsxref("Object.assign()")}} 函数:

-
var obj1 = { foo: 'bar', x: 42 };
+
var obj1 = { foo: 'bar', x: 42 };
 var obj2 = { foo: 'baz', y: 13 };
 const merge = ( ...objects ) => ( { ...objects } );
 
@@ -191,7 +191,7 @@ var mergedObj = merge ( {}, obj1, obj2);
 
 

在数组或函数参数中使用展开语法时, 该语法只能用于 可迭代对象

-
var obj = {'key1': 'value1'};
+
var obj = {'key1': 'value1'};
 var array = [...obj]; // TypeError: obj is not iterable
 
diff --git a/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html b/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html index 125b67c168..1b8211841a 100644 --- a/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html +++ b/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Strict_equality

语法

-
x === y
+
x === y

描述

@@ -39,7 +39,7 @@ translation_of: Web/JavaScript/Reference/Operators/Strict_equality

比较相同类型的操作数

-
console.log("hello" === "hello");   // true
+
console.log("hello" === "hello");   // true
 console.log("hello" === "hola");    // false
 
 console.log(3 === 3);               // true
@@ -52,7 +52,7 @@ console.log(null === null);         // true

比较不同类型的操作数

-
console.log("3" === 3);           // false
+
console.log("3" === 3);           // false
 
 console.log(true === 1);          // false
 
@@ -60,7 +60,7 @@ console.log(null === undefined);  // false

比较对象

-
const object1 = {
+
const object1 = {
   name: "hello"
 }
 
diff --git a/files/zh-cn/web/javascript/reference/operators/strict_inequality/index.html b/files/zh-cn/web/javascript/reference/operators/strict_inequality/index.html
index a31aa575d1..26efd1748f 100644
--- a/files/zh-cn/web/javascript/reference/operators/strict_inequality/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/strict_inequality/index.html
@@ -13,13 +13,13 @@ translation_of: Web/JavaScript/Reference/Operators/Strict_inequality
 
 

语法

-
x !== y
+
x !== y

描述

严格不等式运算符检查其对象是否不相等。它是严格相等运算符的否定,因此下面两行总是会给出相同的结果:

-
x !== y
+
x !== y
 
 !(x === y)
@@ -27,13 +27,13 @@ translation_of: Web/JavaScript/Reference/Operators/Strict_inequality

与严格相等运算符一样,严格不等运算符始终认为不同类型的对象是不同的:

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

示例

比较相同类型的对象

-
console.log("hello" !== "hello");   // false
+
console.log("hello" !== "hello");   // false
 console.log("hello" !== "hola");    // true
 
 console.log(3 !== 3);               // false
@@ -46,7 +46,7 @@ console.log(null !== null);         // false

比较不同类型的对象

-
console.log("3" !== 3);           // true
+
console.log("3" !== 3);           // true
 
 console.log(true !== 1);          // true
 
@@ -54,7 +54,7 @@ console.log(null !== undefined);  // true

比较Object对象

-
const object1 = {
+
const object1 = {
   name: "hello"
 }
 
diff --git a/files/zh-cn/web/javascript/reference/operators/subtraction/index.html b/files/zh-cn/web/javascript/reference/operators/subtraction/index.html
index 00dcee2a1e..c4307e2ace 100644
--- a/files/zh-cn/web/javascript/reference/operators/subtraction/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/subtraction/index.html
@@ -15,19 +15,19 @@ translation_of: Web/JavaScript/Reference/Operators/Subtraction
 
 

语法

-
Operator: x - y
+
Operator: x - y
 

Examples

Subtraction with numbers

-
5 - 3     // 2
+
5 - 3     // 2
 3 - 5     // -2

Subtraction with non-numbers

-
'foo' - 3 // NaN
+
'foo' - 3 // NaN

Specifications

diff --git a/files/zh-cn/web/javascript/reference/operators/subtraction_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/subtraction_assignment/index.html index 93dc5a138b..9d96a67f7e 100644 --- a/files/zh-cn/web/javascript/reference/operators/subtraction_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/subtraction_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Subtraction_assignment

语法

-
Operator: x -= y
+
Operator: x -= y
 Meaning:  x  = x - y

Examples

Using subtraction assignment

-
// Assuming the following variable
+
// Assuming the following variable
 //  bar = 5
 
 bar -= 2     // 3
diff --git a/files/zh-cn/web/javascript/reference/operators/super/index.html b/files/zh-cn/web/javascript/reference/operators/super/index.html
index 1f279cb42f..ba936e09ba 100644
--- a/files/zh-cn/web/javascript/reference/operators/super/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/super/index.html
@@ -16,7 +16,7 @@ translation_of: Web/JavaScript/Reference/Operators/super
 
 

语法

-
super([arguments]);
+
super([arguments]);
 // 调用 父对象/父类 的构造函数
 
 super.functionOnParent([arguments]);
@@ -33,7 +33,7 @@ super.functionOnParent([arguments]);
 
 

以下代码片段来自于 classes sample

-
class Polygon {
+
class Polygon {
   constructor(height, width) {
     this.name = 'Rectangle';
     this.height = height;
@@ -69,7 +69,7 @@ class Square extends Polygon {
 
 

你也可以用 super 调用父类的静态方法

-
class Rectangle {
+
class Rectangle {
   constructor() {}
   static logNbSides() {
     return 'I have 4 sides';
@@ -88,7 +88,7 @@ Square.logDescription(); // 'I have 4 sides which are all equal'

你不能使用 delete 操作符 加 super.prop 或者 super[expr] 去删除父类的属性,这样做会抛出 {{jsxref("ReferenceError")}}。

-
class Base {
+
class Base {
   constructor() {}
   foo() {}
 }
@@ -105,7 +105,7 @@ new Derived().delete(); // ReferenceError: invalid delete involving 'super'.当使用 {{jsxref("Object.defineProperty")}} 定义一个属性为不可写时,super将不能重写这个属性的值。

-
class X {
+
class X {
   constructor() {
     Object.defineProperty(this, 'prop', {
       configurable: true,
@@ -132,7 +132,7 @@ console.log(y.prop); // 1

Super也可以在object initializer / literal 符号中使用。在下面的例子中,两个对象各定义了一个方法。在第二个对象中, 我们使用super调用了第一个对象中的方法。 当然,这需要我们先利用 {{jsxref("Object.setPrototypeOf()")}} 设置obj2的原型为obj1,然后才能够使用super调用 obj1上的method1

-
var obj1 = {
+
var obj1 = {
   method1() {
     console.log("method 1");
   }
diff --git a/files/zh-cn/web/javascript/reference/operators/this/index.html b/files/zh-cn/web/javascript/reference/operators/this/index.html
index aea931541f..86616407d0 100644
--- a/files/zh-cn/web/javascript/reference/operators/this/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/this/index.html
@@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Operators/this
 
 

语法

-
this
+
this

@@ -32,7 +32,7 @@ translation_of: Web/JavaScript/Reference/Operators/this

无论是否在严格模式下,在全局执行环境中(在任何函数体外部)this 都指向全局对象。

-
// 在浏览器中, window 对象同时也是全局对象:
+
// 在浏览器中, window 对象同时也是全局对象:
 console.log(this === window); // true
 
 a = 37;
@@ -52,7 +52,7 @@ console.log(b)         // "MDN"

因为下面的代码不在严格模式下,且 this 的值不是由该调用设置的,所以 this 的值默认指向全局对象,浏览器中就是 {{domxref("Window", "window")}}。

-
function f1(){
+
function f1(){
   return this;
 }
 //在浏览器中:
@@ -64,7 +64,7 @@ f1() === globalThis;
 
 

然而,在严格模式下,如果进入执行环境时没有设置 this 的值,this 会保持为 undefined,如下:

-
function f2(){
+
function f2(){
   "use strict"; // 这里是严格模式
   return this;
 }
@@ -82,7 +82,7 @@ f2() === undefined; // true
 
 

在类的构造函数中,this 是一个常规对象。类中所有非静态的方法都会被添加到 this 的原型中:

-
class Example {
+
class Example {
   constructor() {
     const proto = Object.getPrototypeOf(this);
     console.log(Object.getOwnPropertyNames(proto));
@@ -102,7 +102,7 @@ new Example(); // ['constructor', 'first', 'second']

不像基类的构造函数,派生类的构造函数没有初始的 this 绑定。在构造函数中调用 {{jsxref("Operators/super", "super()")}} 会生成一个 this 绑定,并相当于执行如下代码,Base为基类:

-
this = new Base();
+
this = new Base();

警告:在调用 super() 之前引用 this 会抛出错误。

@@ -110,7 +110,7 @@ new Example(); // ['constructor', 'first', 'second']

派生类不能在调用 super() 之前返回,除非其构造函数返回的是一个对象,或者根本没有构造函数。

-
class Base {}
+
class Base {}
 class Good extends Base {}
 class AlsoGood extends Base {
   constructor() {
@@ -147,7 +147,7 @@ whatsThis.apply(obj); // 'Custom' 因为函数中的 this 被设置为obj
 
 

this 和对象转换

-
function add(c, d) {
+
function add(c, d) {
   return this.a + this.b + c + d;
 }
 
@@ -164,7 +164,7 @@ add.apply(o, [10, 20]); // 34
 
 

在非严格模式下使用 call 和 apply 时,如果用作 this 的值不是对象,则会被尝试转换为对象。null 和 undefined 被转换为全局对象。原始值如 7 或 'foo' 会使用相应构造函数转换为对象。因此 7 会被转换为 new Number(7) 生成的对象,字符串 'foo' 会转换为 new String('foo') 生成的对象。

-
function bar() {
+
function bar() {
   console.log(Object.prototype.toString.call(this));
 }
 
@@ -176,7 +176,7 @@ bar.call(undefined); // [object global]

ECMAScript 5 引入了 {{jsxref("Function.prototype.bind()")}}。调用f.bind(someObject)会创建一个与f具有相同函数体和作用域的函数,但是在这个新函数中,this将永久地被绑定到了bind的第一个参数,无论这个函数是如何被调用的。

-
function f(){
+
function f(){
   return this.a;
 }
 
@@ -194,7 +194,7 @@ console.log(o.a, o.f(), o.g(), o.h()); // 37, 37, azerty, azerty
 
 

箭头函数中,this与封闭词法环境的this保持一致。在全局代码中,它将被设置为全局对象:

-
var globalObject = this;
+
var globalObject = this;
 var foo = (() => this);
 console.log(foo() === globalObject); // true
@@ -202,7 +202,7 @@ console.log(foo() === globalObject); // true

注意:如果将this传递给callbind、或者apply来调用箭头函数,它将被忽略。不过你仍然可以为调用添加参数,不过第一个参数(thisArg)应该设置为null

-
// 接着上面的代码
+
// 接着上面的代码
 // 作为对象的一个方法调用
 var obj = {foo: foo};
 console.log(obj.foo() === globalObject); // true
@@ -216,7 +216,7 @@ console.log(foo() === globalObject); // true

无论如何,foo 的 this 被设置为他被创建时的环境(在上面的例子中,就是全局对象)。这同样适用于在其他函数内创建的箭头函数:这些箭头函数的this被设置为封闭的词法环境的。

-
// 创建一个含有bar方法的obj对象,
+
// 创建一个含有bar方法的obj对象,
 // bar返回一个函数,
 // 这个函数返回this,
 // 这个返回的函数是以箭头函数创建的,
@@ -252,7 +252,7 @@ console.log(fn2()() == window); // true

下面的例子中,当 o.f() 被调用时,函数内的 this 将绑定到 o 对象。

-
var o = {
+
var o = {
   prop: 37,
   f: function() {
     return this.prop;
@@ -264,7 +264,7 @@ console.log(o.f()); // 37
 
 

请注意,这样的行为完全不会受函数定义方式或位置的影响。在前面的例子中,我们在定义对象o的同时,将其中的函数定义为成员 f 。但是,我们也可以先定义函数,然后再将其附属到o.f。这样做的结果是一样的:

-
var o = {prop: 37};
+
var o = {prop: 37};
 
 function independent() {
   return this.prop;
@@ -279,14 +279,14 @@ console.log(o.f()); // 37
 
 

同样,this 的绑定只受最接近的成员引用的影响。在下面的这个例子中,我们把一个方法g当作对象o.b的函数调用。在这次执行期间,函数中的this将指向o.b。事实证明,这与他是对象 o 的成员没有多大关系,最近的引用才是最重要的。

-
o.b = {g: independent, prop: 42};
+
o.b = {g: independent, prop: 42};
 console.log(o.b.g()); // 42

原型链中的 this

对于在对象原型链上某处定义的方法,同样的概念也适用。如果该方法存在于一个对象的原型链上,那么 this 指向的是调用这个方法的对象,就像该方法就在这个对象上一样。

-
var o = {
+
var o = {
   f: function() {
     return this.a + this.b;
   }
@@ -304,7 +304,7 @@ console.log(p.f()); // 5
 
 

再次,相同的概念也适用于当函数在一个 getter 或者 setter 中被调用。用作 getter 或 setter 的函数都会把 this 绑定到设置或获取属性的对象。

-
function sum() {
+
function sum() {
   return this.a + this.b + this.c;
 }
 
@@ -331,7 +331,7 @@ console.log(o.average, o.sum); // logs 2, 6
 

虽然构造函数返回的默认值是 this 所指的那个对象,但它仍可以手动返回其他的对象(如果返回值不是一个对象,则返回 this 对象)。

-
/*
+
/*
  * 构造函数这样工作:
  *
  * function MyConstructor(){
@@ -370,7 +370,7 @@ console.log(o.a); // logs 38
 
 

当函数被用作事件处理函数时,它的 this 指向触发事件的元素(一些浏览器在使用非 addEventListener 的函数动态地添加监听函数时不遵守这个约定)。

-
// 被调用时,将关联的元素变成蓝色
+
// 被调用时,将关联的元素变成蓝色
 function bluify(e){
   console.log(this === e.currentTarget); // 总是 true
 
@@ -391,14 +391,14 @@ for(var i=0 ; i<elements.length ; i++){
 
 

当代码被内联 on-event 处理函数 调用时,它的this指向监听器所在的DOM元素:

-
<button onclick="alert(this.tagName.toLowerCase());">
+
<button onclick="alert(this.tagName.toLowerCase());">
   Show this
 </button>
 

上面的 alert 会显示 button。注意只有外层代码中的 this 是这样设置的:

-
<button onclick="alert((function(){return this})());">
+
<button onclick="alert((function(){return this})());">
   Show inner this
 </button>
 
@@ -409,7 +409,7 @@ for(var i=0 ; i<elements.length ; i++){

和其他普通函数一样,方法中的 this 值取决于它们如何被调用。有时,改写这个行为,让类中的 this 值总是指向这个类实例会很有用。为了做到这一点,可在构造函数中绑定类方法:

-
class Car {
+
class Car {
   constructor() {
     // Bind sayBye but not sayHi to show the difference
     this.sayBye = this.sayBye.bind(this);
diff --git a/files/zh-cn/web/javascript/reference/operators/typeof/index.html b/files/zh-cn/web/javascript/reference/operators/typeof/index.html
index 41cf3c8da9..60cd51b992 100644
--- a/files/zh-cn/web/javascript/reference/operators/typeof/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/typeof/index.html
@@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Operators/typeof
 
 

typeof 运算符后接操作数:

-
typeof operand
+
typeof operand
 typeof(operand)
 
@@ -88,7 +88,7 @@ typeof(operand)

示例

-
// 数值
+
// 数值
 typeof 37 === 'number';
 typeof 3.14 === 'number';
 typeof(42) === 'number';
@@ -152,7 +152,7 @@ typeof Math.sin === 'function';
 
 

typeof null

-
// JavaScript 诞生以来便如此
+
// JavaScript 诞生以来便如此
 typeof null === 'object';

在 JavaScript 最初的实现中,JavaScript 中的值是由一个表示类型的标签和实际数据值表示的。对象的类型标签是 0。由于 null 代表的是空指针(大多数平台下值为 0x00),因此,null 的类型标签是 0,typeof null 也因此返回 "object"。(参考来源

@@ -161,7 +161,7 @@ typeof null === 'object';

使用 new 操作符

-
// 除 Function 外的所有构造函数的类型都是 'object'
+
// 除 Function 外的所有构造函数的类型都是 'object'
 var str = new String('String');
 var num = new Number(100);
 
@@ -174,7 +174,7 @@ typeof func; // 返回 'function'

语法中的括号

-
// 括号有无将决定表达式的类型。
+
// 括号有无将决定表达式的类型。
 var iData = 99;
 
 typeof iData + ' Wisen'; // 'number Wisen'
@@ -184,7 +184,7 @@ typeof (iData + ' Wisen'); // 'string'

对正则表达式字面量的类型判断在某些浏览器中不符合标准:

-
typeof /s/ === 'function'; // Chrome 1-12 , 不符合 ECMAScript 5.1
+
typeof /s/ === 'function'; // Chrome 1-12 , 不符合 ECMAScript 5.1
 typeof /s/ === 'object'; // Firefox 5+ , 符合 ECMAScript 5.1
 
@@ -194,7 +194,7 @@ typeof /s/ === 'object'; // Firefox 5+ , 符合 ECMAScript 5.1

但在加入了块级作用域的 let 和 const 之后,在其被声明之前对块中的 let 和 const 变量使用 typeof 会抛出一个 ReferenceError。块作用域变量在块的头部处于“暂存死区”,直至其被初始化,在这期间,访问变量将会引发错误。

-
typeof undeclaredVariable === 'undefined';
+
typeof undeclaredVariable === 'undefined';
 
 typeof newLetVariable; // ReferenceError
 typeof newConstVariable; // ReferenceError
@@ -208,7 +208,7 @@ class newClass{};

当前所有的浏览器都暴露了一个类型为 undefined 的非标准宿主对象 {{domxref("document.all")}}。

-
typeof document.all === 'undefined';
+
typeof document.all === 'undefined';
 

尽管规范允许为非标准的外来对象自定义类型标签,但它要求这些类型标签与已有的不同。document.all 的类型标签为 'undefined' 的例子在 Web 领域中被归类为对原 ECMA JavaScript 标准的“故意侵犯”。

@@ -219,7 +219,7 @@ class newClass{};

For greater specificity in checking types, a typeof wrapper for usage in production-level code would be as follows (provided obj exists):

-
  function type(obj, fullClass) {
+
  function type(obj, fullClass) {
 
     // get toPrototypeString() of obj (handles all types)
     // Early JS environments return '[object Object]' for null, so it's best to directly check for it.
@@ -265,7 +265,7 @@ class newClass{};

在 IE 6, 7 和 8 上,很多宿主对象是对象而不是函数。例如:

-
typeof alert === 'object'
+
typeof alert === 'object'
diff --git a/files/zh-cn/web/javascript/reference/operators/unary_negation/index.html b/files/zh-cn/web/javascript/reference/operators/unary_negation/index.html index 2170b92c53..887a79a2a0 100644 --- a/files/zh-cn/web/javascript/reference/operators/unary_negation/index.html +++ b/files/zh-cn/web/javascript/reference/operators/unary_negation/index.html @@ -13,14 +13,14 @@ translation_of: Web/JavaScript/Reference/Operators/Unary_negation

语法

-
Operator: -x
+
Operator: -x
 

Examples

Negating numbers

-
const x = 3;
+
const x = 3;
 const y = -x;
 
 // y = -3
@@ -31,7 +31,7 @@ const y = -x;
 
 

The unary negation operator can convert a non-number into a number.

-
const x = "4";
+
const x = "4";
 const y = -x;
 
 // y = -4
diff --git a/files/zh-cn/web/javascript/reference/operators/unary_plus/index.html b/files/zh-cn/web/javascript/reference/operators/unary_plus/index.html
index 9f3b818df9..da09fa1f02 100644
--- a/files/zh-cn/web/javascript/reference/operators/unary_plus/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/unary_plus/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Unary_plus
 
 

语法

-
Operator: +x
+
Operator: +x
 

Description

@@ -24,7 +24,7 @@ translation_of: Web/JavaScript/Reference/Operators/Unary_plus

Usage with numbers

-
const x = 1;
+
const x = 1;
 const y = -1;
 
 console.log(+x);
@@ -34,7 +34,7 @@ console.log(+y);
 
 

Usage with non-numbers

-
+true  // 1
+
+true  // 1
 +false // 0
 +null  // 0
 +function(val){ return val } // NaN
diff --git a/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift/index.html b/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift/index.html
index f40a28e8b0..52f18ea92c 100644
--- a/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Unsigned_right_shift
 
 

语法

-
a >>> b
+
a >>> b
 

描述

@@ -22,14 +22,14 @@ translation_of: Web/JavaScript/Reference/Operators/Unsigned_right_shift

For non-negative numbers, zero-fill right shift and sign-propagating right shift yield the same result. For example, 9 >>> 2 yields 2, the same as 9 >> 2:

-
.     9 (base 10): 00000000000000000000000000001001 (base 2)
+
.     9 (base 10): 00000000000000000000000000001001 (base 2)
                    --------------------------------
 9 >>> 2 (base 10): 00000000000000000000000000000010 (base 2) = 2 (base 10)
 

However, this is not the case for negative numbers. For example, -9 >>> 2 yields 1073741821, which is different than -9 >> 2 (which yields -3):

-
.     -9 (base 10): 11111111111111111111111111110111 (base 2)
+
.     -9 (base 10): 11111111111111111111111111110111 (base 2)
                     --------------------------------
 -9 >>> 2 (base 10): 00111111111111111111111111111101 (base 2) = 1073741821 (base 10)
 
@@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Operators/Unsigned_right_shift

Using unsigned right shift

-
 9 >>> 2; // 2
+
 9 >>> 2; // 2
 -9 >>> 2; // 1073741821
 
diff --git a/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift_assignment/index.html index 76379358c0..0c2e1fb3c5 100644 --- a/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Unsigned_right_shift_assignme

语法

-
Operator: x >>>= y
+
Operator: x >>>= y
 Meaning:  x    = x >>> y

例子

Using unsigned right shift assignment

-
let a = 5; //   (00000000000000000000000000000101)
+
let a = 5; //   (00000000000000000000000000000101)
 a >>>= 2;  // 1 (00000000000000000000000000000001)
 
 let b = -5; // (-00000000000000000000000000000101)
-- 
cgit v1.2.3-54-g00ecf