Lưu ý rằng sự khác biệt giữa tất cả những thứ này đều liên quan đến việc xử lý các nguyên mẫu của chúng; . Đối với bất kỳ đối tượng không nguyên thủy nào
const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
9 và // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
0 có cấu trúc giống nhau nhưng bản thân chúng là các đối tượng riêng biệt, tất cả các dạng trên sẽ đánh giá là const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
0Bình đẳng nghiêm ngặt bằng cách sử dụng ===
Bình đẳng nghiêm ngặt so sánh hai giá trị cho bình đẳng. Không có giá trị nào được chuyển đổi hoàn toàn sang một số giá trị khác trước khi được so sánh. Nếu các giá trị có các loại khác nhau, các giá trị được coi là không bằng nhau. Nếu các giá trị có cùng loại, không phải là số và có cùng giá trị thì chúng được coi là bằng nhau. Cuối cùng, nếu cả hai giá trị đều là số, thì chúng được coi là bằng nhau nếu cả hai đều không phải là
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1 và có cùng giá trị hoặc nếu một là console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
3 và một là console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2const num = 0;
const obj = new String["0"];
const str = "0";
console.log[num === num]; // true
console.log[obj === obj]; // true
console.log[str === str]; // true
console.log[num === obj]; // false
console.log[num === str]; // false
console.log[obj === str]; // false
console.log[null === undefined]; // false
console.log[obj === null]; // false
console.log[obj === undefined]; // false
Bình đẳng nghiêm ngặt hầu như luôn luôn là hoạt động so sánh chính xác để sử dụng. Đối với tất cả các giá trị ngoại trừ số, nó sử dụng ngữ nghĩa rõ ràng. một giá trị chỉ bằng chính nó. Đối với các số, nó sử dụng ngữ nghĩa hơi khác nhau để đánh bóng trên hai trường hợp cạnh khác nhau. Đầu tiên là số 0 dấu phẩy động được ký dương hoặc âm. Điều này rất hữu ích trong việc biểu diễn một số nghiệm toán học nhất định, nhưng vì hầu hết các tình huống không quan tâm đến sự khác biệt giữa
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
3 và console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2, đẳng thức nghiêm ngặt coi chúng là cùng một giá trị. Thứ hai là dấu phẩy động bao gồm khái niệm về một giá trị không phải là số, console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1, để biểu thị giải pháp cho một số vấn đề toán học không xác định. vô cực âm được thêm vào vô cực dương, ví dụ. Bình đẳng nghiêm ngặt coi console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1 là không bình đẳng với mọi giá trị khác — bao gồm cả chính nó. [Trường hợp duy nhất mà // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
9 là // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
20 là khi const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
9 là console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1. ]Bên cạnh
const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
63, đẳng thức nghiêm ngặt cũng được sử dụng bởi các phương pháp tìm chỉ mục mảng bao gồm khớp nối // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
24, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
25, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
26, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
27 và // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
28. Điều này có nghĩa là bạn không thể sử dụng // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
29 để tìm chỉ mục của giá trị console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1 trong một mảng hoặc sử dụng console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1 làm giá trị // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
28 trong câu lệnh const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
43 và làm cho nó khớp với bất kỳ thứ gìconsole.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
Bình đẳng lỏng lẻo sử dụng ==
Bình đẳng lỏng lẻo là đối xứng.
const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
44 luôn có ngữ nghĩa giống hệt với const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
45 đối với bất kỳ giá trị nào của const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
46 và const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
47 [ngoại trừ thứ tự chuyển đổi được áp dụng]. Hành vi để thực hiện bình đẳng lỏng lẻo bằng cách sử dụng const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
64 như sau- Nếu các toán hạng có cùng kiểu, chúng được so sánh như sau
- Sự vật. chỉ trả về
20 nếu cả hai toán hạng tham chiếu cùng một đối tượng// Add an immutable NEGATIVE_ZERO property to the Number constructor. Object.defineProperty[Number, "NEGATIVE_ZERO", { value: -0, writable: false, configurable: false, enumerable: false, }]; function attemptMutation[v] { Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }]; }
- Sợi dây. chỉ trả về
20 nếu cả hai toán hạng có cùng ký tự theo cùng một thứ tự// Add an immutable NEGATIVE_ZERO property to the Number constructor. Object.defineProperty[Number, "NEGATIVE_ZERO", { value: -0, writable: false, configurable: false, enumerable: false, }]; function attemptMutation[v] { Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }]; }
- Con số. chỉ trả về
20 nếu cả hai toán hạng có cùng giá trị.// Add an immutable NEGATIVE_ZERO property to the Number constructor. Object.defineProperty[Number, "NEGATIVE_ZERO", { value: -0, writable: false, configurable: false, enumerable: false, }]; function attemptMutation[v] { Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }]; }
3 vàconsole.log[[NaN].indexOf[NaN]]; // -1 switch [NaN] { case NaN: console.log["Surprise"]; // Nothing is logged }
2 được coi là cùng một giá trị. Nếu một trong hai toán hạng làconsole.log[[NaN].indexOf[NaN]]; // -1 switch [NaN] { case NaN: console.log["Surprise"]; // Nothing is logged }
1, trả vềconsole.log[[NaN].indexOf[NaN]]; // -1 switch [NaN] { case NaN: console.log["Surprise"]; // Nothing is logged }
0;const num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
- Boolean. trả lại
20 chỉ khi toán hạng là cả hai// Add an immutable NEGATIVE_ZERO property to the Number constructor. Object.defineProperty[Number, "NEGATIVE_ZERO", { value: -0, writable: false, configurable: false, enumerable: false, }]; function attemptMutation[v] { Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }]; }
20 hoặc cả hai// Add an immutable NEGATIVE_ZERO property to the Number constructor. Object.defineProperty[Number, "NEGATIVE_ZERO", { value: -0, writable: false, configurable: false, enumerable: false, }]; function attemptMutation[v] { Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }]; }
0const num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
- BigInt. chỉ trả về
20 nếu cả hai toán hạng có cùng giá trị// Add an immutable NEGATIVE_ZERO property to the Number constructor. Object.defineProperty[Number, "NEGATIVE_ZERO", { value: -0, writable: false, configurable: false, enumerable: false, }]; function attemptMutation[v] { Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }]; }
- Biểu tượng. chỉ trả về
20 nếu cả hai toán hạng tham chiếu cùng một ký hiệu// Add an immutable NEGATIVE_ZERO property to the Number constructor. Object.defineProperty[Number, "NEGATIVE_ZERO", { value: -0, writable: false, configurable: false, enumerable: false, }]; function attemptMutation[v] { Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }]; }
- Sự vật. chỉ trả về
- Nếu một trong các toán hạng là
633 hoặcconst num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
634, thì toán hạng kia cũng phải làconst num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
633 hoặcconst num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
634 để trả vềconst num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
20. Nếu không thì trả lại// Add an immutable NEGATIVE_ZERO property to the Number constructor. Object.defineProperty[Number, "NEGATIVE_ZERO", { value: -0, writable: false, configurable: false, enumerable: false, }]; function attemptMutation[v] { Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }]; }
0const num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
- Nếu một trong các toán hạng là đối tượng và toán hạng kia là nguyên thủy, hãy chuyển đối tượng thành nguyên thủy
- Ở bước này, cả hai toán hạng được chuyển đổi thành nguyên hàm [một trong Chuỗi, Số, Boolean, Ký hiệu và BigInt]. Phần còn lại của việc chuyển đổi được thực hiện theo từng trường hợp
- Nếu chúng cùng loại, hãy so sánh chúng bằng bước 1
- Nếu một trong các toán hạng là Ký hiệu còn toán hạng kia thì không, trả về
0const num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
- Nếu một trong các toán hạng là Boolean nhưng toán hạng kia thì không, hãy chuyển đổi boolean thành một số.
20 được chuyển thành 1 và// Add an immutable NEGATIVE_ZERO property to the Number constructor. Object.defineProperty[Number, "NEGATIVE_ZERO", { value: -0, writable: false, configurable: false, enumerable: false, }]; function attemptMutation[v] { Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }]; }
0 được chuyển thành 0. Sau đó so sánh lỏng lẻo hai toán hạng một lần nữaconst num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
- Số thành chuỗi. chuyển chuỗi thành số. Lỗi chuyển đổi dẫn đến
1, điều này sẽ đảm bảo đẳng thức làconsole.log[[NaN].indexOf[NaN]]; // -1 switch [NaN] { case NaN: console.log["Surprise"]; // Nothing is logged }
0const num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
- Số đến BigInt. so sánh bằng giá trị số của chúng. Nếu số là ±Infinity hoặc
1, hãy trả vềconsole.log[[NaN].indexOf[NaN]]; // -1 switch [NaN] { case NaN: console.log["Surprise"]; // Nothing is logged }
0const num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
- Chuỗi thành BigInt. chuyển đổi chuỗi thành BigInt bằng thuật toán tương tự như hàm tạo
646. Nếu chuyển đổi không thành công, hãy trả lạiconst num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
0const num = 0; const big = 0n; const str = "0"; const obj = new String["0"]; console.log[num == str]; // true console.log[big == num]; // true console.log[str == big]; // true console.log[num == obj]; // true console.log[big == obj]; // true console.log[str == obj]; // true
Theo truyền thống và theo ECMAScript, tất cả các đối tượng và đối tượng nguyên thủy đều không bằng nhau đối với
const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
634 và const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
633. Nhưng hầu hết các trình duyệt cho phép một lớp đối tượng rất hẹp [cụ thể là đối tượng const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
720 cho bất kỳ trang nào], trong một số ngữ cảnh, hoạt động như thể chúng mô phỏng giá trị const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
634. Bình đẳng lỏng lẻo là một trong những bối cảnh như vậy. const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
722 và const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
723 đánh giá là true nếu và chỉ khi A là một đối tượng mô phỏng const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
634. Trong tất cả các trường hợp khác, một đối tượng không bao giờ lỏng lẻo bằng const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
634 hoặc const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
633Trong hầu hết các trường hợp, việc sử dụng đẳng thức lỏng lẻo không được khuyến khích. Kết quả so sánh sử dụng đẳng thức nghiêm ngặt sẽ dễ dự đoán hơn và có thể đánh giá nhanh hơn do không có kiểu ép buộc
Ví dụ sau đây minh họa các so sánh đẳng thức lỏng lẻo liên quan đến số nguyên thủy
const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727, nguyên hàm bigint const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
728, nguyên hàm chuỗi const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
729 và một đối tượng có giá trị console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
00 là const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
729const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
Đẳng thức lỏng lẻo chỉ được sử dụng bởi toán tử
const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
64Đẳng thức cùng giá trị sử dụng Object. Là[]
Đẳng thức cùng giá trị xác định xem hai giá trị có chức năng giống hệt nhau trong mọi ngữ cảnh hay không. [Trường hợp sử dụng này thể hiện một ví dụ về nguyên tắc thay thế Liskov. ] Một trường hợp xảy ra khi một nỗ lực được thực hiện để thay đổi một thuộc tính không thể thay đổi
// Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
03 sẽ đưa ra một ngoại lệ khi cố gắng thay đổi một thuộc tính không thể thay đổi, nhưng sẽ không có tác dụng gì nếu không có thay đổi thực sự nào được yêu cầu. Nếu console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
04 là console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2, không có thay đổi nào được yêu cầu và sẽ không có lỗi xảy ra. Trong nội bộ, khi một thuộc tính bất biến được xác định lại, giá trị mới được chỉ định được so sánh với giá trị hiện tại bằng cách sử dụng đẳng thức cùng giá trịĐẳng thức cùng giá trị được cung cấp bởi phương pháp
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
06. Nó được sử dụng ở hầu hết mọi nơi trong ngôn ngữ mà giá trị nhận dạng tương đương được mong đợiBình đẳng giá trị bằng không
Tương tự như đẳng thức cùng giá trị, nhưng +0 và -0 được coi là bằng nhau
Đẳng thức cùng giá trị bằng 0 không được hiển thị dưới dạng API JavaScript, nhưng có thể được triển khai bằng mã tùy chỉnh
// Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
2Same-value-zero chỉ khác với đẳng thức nghiêm ngặt bằng cách coi
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1 là tương đương và chỉ khác với đẳng thức cùng giá trị bằng cách coi console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2 tương đương với const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727. Điều này làm cho nó thường có hành vi hợp lý nhất trong quá trình tìm kiếm, đặc biệt là khi làm việc với console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1. Nó được sử dụng bởi các phương pháp console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
11, console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
12, cũng như console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
13 và console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
14 để so sánh đẳng thức chínhSo sánh các phương pháp đẳng thức
Mọi người thường so sánh số bằng gấp đôi và số bằng gấp ba bằng cách nói cái này là phiên bản "nâng cao" của cái kia. Ví dụ: double equals có thể được coi là phiên bản mở rộng của triple equals, bởi vì cái trước làm mọi thứ mà cái sau làm, nhưng với chuyển đổi kiểu trên toán hạng của nó - ví dụ:
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
15. Ngoài ra, có thể khẳng định rằng dấu bằng kép là cơ sở và dấu bằng ba là phiên bản nâng cao, bởi vì nó yêu cầu hai toán hạng phải cùng loại, do đó, nó bổ sung thêm một ràng buộcTuy nhiên, cách suy nghĩ này ngụ ý rằng các so sánh bình đẳng tạo thành một "quang phổ" một chiều trong đó "hoàn toàn nghiêm ngặt" nằm ở một đầu và "hoàn toàn lỏng lẻo" nằm ở đầu kia. Mô hình này không phù hợp với
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
06, bởi vì nó không "lỏng lẻo" hơn so với số bằng gấp đôi hoặc "chặt chẽ hơn" so với số bằng gấp ba, cũng như không phù hợp ở đâu đó ở giữa [i. e. , chặt chẽ hơn gấp đôi bằng, nhưng lỏng lẻo hơn gấp ba bằng]. Chúng ta có thể thấy từ bảng so sánh sự giống nhau bên dưới rằng điều này là do cách mà console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
06 xử lý console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1. Lưu ý rằng nếu console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
19 được đánh giá bằng const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
0, chúng ta có thể nói rằng nó phù hợp với phổ lỏng lẻo/nghiêm ngặt dưới dạng một dạng thậm chí còn chặt chẽ hơn của bộ ba bằng, một dạng phân biệt giữa console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2 và console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
3. Việc xử lý console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1 có nghĩa là điều này là không đúng sự thật, tuy nhiên. Thật không may, console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
06 phải được xem xét theo các đặc điểm cụ thể của nó, thay vì tính lỏng lẻo hoặc nghiêm ngặt của nó đối với các toán tử đẳng thứcxyconst num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
64const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
63console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
06console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
28const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
634const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
634console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
633const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
633console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31// Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
20// Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
20console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
0const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
0console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
53console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
53console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
3console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
3const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
728console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
84console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
0console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
95const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
0console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
95const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
729const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
69const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
13const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
14___ Khi nào nên sử dụng đối tượng. is[] so với ba bằng
Nói chung, hành vi đặc biệt của
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
06 đối với số 0 chỉ có thể được quan tâm khi theo đuổi một số sơ đồ lập trình meta nhất định, đặc biệt là liên quan đến các bộ mô tả thuộc tính, khi công việc của bạn mong muốn phản ánh một số đặc điểm của console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
03. Nếu trường hợp sử dụng của bạn không yêu cầu điều này, bạn nên tránh sử dụng console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
06 và thay vào đó sử dụng const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
63. Ngay cả khi các yêu cầu của bạn liên quan đến việc so sánh giữa hai giá trị console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1 đánh giá với // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
20, nhìn chung, việc kiểm tra trường hợp đặc biệt của console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1 [sử dụng phương pháp const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
92 có sẵn từ các phiên bản trước của ECMAScript] sẽ dễ dàng hơn so với việc tìm ra cách các tính toán xung quanh có thể ảnh hưởng đến Dưới đây là danh sách chưa đầy đủ các phương thức và toán tử tích hợp có thể gây ra sự khác biệt giữa
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2 và console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
3 tự hiển thị trong mã của bạnconst num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
95 [phủ định đơn nguyên]Xem xét ví dụ sau
const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
4Nếu
const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
96 là const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727 [hoặc tính thành const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
727], một console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2 được đưa vào tại vị trí đó và truyền ra thành // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
00// Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
01, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
02, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
03, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
04Trong một số trường hợp, có thể đưa
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2 vào một biểu thức dưới dạng giá trị trả về của các phương thức này ngay cả khi không tồn tại console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2 dưới dạng một trong các tham số. Ví dụ: sử dụng // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
03 để nâng // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
08 lên lũy thừa của bất kỳ số mũ lẻ, âm nào sẽ đánh giá thành console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2. Tham khảo tài liệu cho các phương pháp riêng lẻ// Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
10, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
11, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
12, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
13, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
14, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
15Có thể nhận được giá trị trả về
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2 từ các phương thức này trong một số trường hợp khi tồn tại console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2 dưới dạng một trong các tham số. e. g. , // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
18 đánh giá thành console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2. Tham khảo tài liệu cho các phương pháp riêng lẻ// Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
20, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
21, // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
22Mỗi toán tử này sử dụng thuật toán ToInt32 trong nội bộ. Vì chỉ có một đại diện cho 0 trong loại số nguyên 32 bit bên trong, nên
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2 sẽ không tồn tại một chuyến đi khứ hồi sau một phép toán nghịch đảo. e. g. , cả // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
24 và // Add an immutable NEGATIVE_ZERO property to the Number constructor.
Object.defineProperty[Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
}];
function attemptMutation[v] {
Object.defineProperty[Number, "NEGATIVE_ZERO", { value: v }];
}
25 đều đánh giá bằng const num = 0;
const big = 0n;
const str = "0";
const obj = new String["0"];
console.log[num == str]; // true
console.log[big == num]; // true
console.log[str == big]; // true
console.log[num == obj]; // true
console.log[big == obj]; // true
console.log[str == obj]; // true
0Việc dựa vào
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
06 khi không tính đến chữ ký của các số 0 có thể gây nguy hiểm. Tất nhiên, khi mục đích là để phân biệt giữa console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
2 và console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
3, nó sẽ thực hiện chính xác những gì mong muốnbáo trước. Sự vật. là [] và NaN
Đặc tả
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
06 coi tất cả các trường hợp của console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1 là cùng một đối tượng. Tuy nhiên, vì có sẵn các mảng đã nhập, nên chúng ta có thể có các biểu diễn dấu chấm động riêng biệt của console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN: console.log["Surprise"]; // Nothing is logged
}
1 không hoạt động giống hệt nhau trong mọi ngữ cảnh. Ví dụ