Có cách nào để kiểm tra xem ba [hoặc nhiều] biến có giống hệt nhau như bạn có thể làm trong Python không?
if var1 == var2 == var3:
pass
Cách thanh lịch nhất để làm điều này trong GDScript là gì?
if var1 == 'string' and var2 == 'string' and var3 == 'string':
pass
Cảm ơn. -]
Chọn một trang web để nhận nội dung đã dịch nếu có và xem các sự kiện và ưu đãi tại địa phương. Dựa trên vị trí của bạn, chúng tôi khuyên bạn nên chọn.
Bạn cũng có thể chọn một trang web từ danh sách sau
Làm thế nào để có được hiệu suất trang web tốt nhất
Chọn trang Trung Quốc [bằng tiếng Trung hoặc tiếng Anh] để có hiệu suất trang tốt nhất. Các trang web quốc gia khác của MathWorks không được tối ưu hóa cho các lượt truy cập từ vị trí của bạn
Công cụ sau đây trực quan hóa những gì máy tính đang làm từng bước khi nó thực thi chương trình nói trên
Dung dịch mẫu-2
Mã Python
def multiple_variables_equality[*vars]:
for x in vars:
if x != vars[0]:
return "All variables have not same value."
return "All variables have same value."
print[multiple_variables_equality[2,3,2,2,2,2]]
print[multiple_variables_equality[10,10,10,10]]
print[multiple_variables_equality[-3,-3,-3,-3]]
Đầu ra mẫu
All variables have not same value. All variables have same value. All variables have same value.
Sơ đồ
Trực quan hóa việc thực thi mã Python
Công cụ sau đây trực quan hóa những gì máy tính đang làm từng bước khi nó thực thi chương trình nói trên
Trình chỉnh sửa mã Python
Có một cách khác để giải quyết giải pháp này?
Trước. Viết chương trình Python để xác định số nguyên lớn nhất và nhỏ nhất, long, float
Kế tiếp. Viết chương trình Python tính tổng tất cả các số trong một tập hợp
Mức độ khó của bài tập này là gì?
Kiểm tra kỹ năng Lập trình của bạn với bài kiểm tra của w3resource
Theo dõi chúng tôi trên Facebook và Twitter để cập nhật thông tin mới nhất.
con trăn. Lời khuyên trong ngày
Phân hủy một bộ sưu tập
Giả sử chúng ta có một hàm trả về một bộ gồm hai giá trị và chúng ta muốn gán mỗi giá trị cho một biến riêng biệt. Một cách là sử dụng lập chỉ mục như dưới đây
abc = [5, 10] x = abc[0] y = abc[1] print[x, y]
đầu ra
5 10
Có một tùy chọn tốt hơn cho phép chúng tôi thực hiện thao tác tương tự trong một dòng
x, y = abc print[x, y]
đầu ra
5 10
Nó có thể được mở rộng thành một bộ có nhiều hơn 2 giá trị hoặc một số cấu trúc dữ liệu khác như danh sách hoặc bộ
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á 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
0Bì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à _______11_______1 và có cùng giá trị hoặc nếu một giá trị là ____11_______3 và một giá trị là ____11_______2
const 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 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ị lời giải cho một số bài toán 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à trong đó // 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à function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
0 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 ===
, đẳng thức nghiêm ngặt cũng được sử dụng bởi các phương pháp tìm kiếm chỉ mục mảng bao gồm
function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
4, function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
5, function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
6, function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
7 và khớp với function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
8. Điều này có nghĩa là bạn không thể sử dụng function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
9 để 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ị function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
8 trong câu lệnh const stoppingForce = obj.mass * -obj.velocity;
3 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 là đối xứng.
const stoppingForce = obj.mass * -obj.velocity;
4 luôn có ngữ nghĩa giống hệt với const stoppingForce = obj.mass * -obj.velocity;
5 đối với bất kỳ giá trị nào của const stoppingForce = obj.mass * -obj.velocity;
6 và const stoppingForce = obj.mass * -obj.velocity;
7 [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 ==
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ề
0 nếu cả hai toán hạng tham chiếu cùng một đối tượngfunction sameValueZero[x, y] { if [typeof x === "number" && typeof y === "number"] { // x and y are equal [may be -0 and 0] or they are both NaN return x === y || [x !== x && y !== y]; } return x === y; }
- Sợi dây. chỉ trả lại
0 nếu cả hai toán hạng có cùng ký tự theo cùng một thứ tựfunction sameValueZero[x, y] { if [typeof x === "number" && typeof y === "number"] { // x and y are equal [may be -0 and 0] or they are both NaN return x === y || [x !== x && y !== y]; } return x === y; }
- Số. chỉ trả về
0 nếu cả hai toán hạng có cùng giá trị.function sameValueZero[x, y] { if [typeof x === "number" && typeof y === "number"] { // x and y are equal [may be -0 and 0] or they are both NaN return x === y || [x !== x && y !== y]; } return x === y; }
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
0 chỉ khi toán hạng là cả haifunction sameValueZero[x, y] { if [typeof x === "number" && typeof y === "number"] { // x and y are equal [may be -0 and 0] or they are both NaN return x === y || [x !== x && y !== y]; } return x === y; }
0 hoặc cả haifunction sameValueZero[x, y] { if [typeof x === "number" && typeof y === "number"] { // x and y are equal [may be -0 and 0] or they are both NaN return x === y || [x !== x && y !== y]; } return x === y; }
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ề
0 nếu cả hai toán hạng có cùng giá trịfunction sameValueZero[x, y] { if [typeof x === "number" && typeof y === "number"] { // x and y are equal [may be -0 and 0] or they are both NaN return x === y || [x !== x && y !== y]; } return x === y; }
- Biểu tượng. chỉ trả về
0 nếu cả hai toán hạng tham chiếu cùng một ký hiệufunction sameValueZero[x, y] { if [typeof x === "number" && typeof y === "number"] { // x and y are equal [may be -0 and 0] or they are both NaN return x === y || [x !== x && y !== y]; } return x === y; }
- Sự vật. chỉ trả về
- Nếu một trong các toán hạng là
===
3 hoặc===
4, thì toán hạng kia cũng phải là===
3 hoặc===
4 để trả về
0. Nếu không thì trả lạifunction sameValueZero[x, y] { if [typeof x === "number" && typeof y === "number"] { // x and y are equal [may be -0 and 0] or they are both NaN return x === y || [x !== x && y !== y]; } return x === y; }
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,
- Ở 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,.
0 được chuyển thành 1 vàfunction sameValueZero[x, y] { if [typeof x === "number" && typeof y === "number"] { // x and y are equal [may be -0 and 0] or they are both NaN return x === y || [x !== x && y !== y]; } return x === y; }
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. . Lỗi chuyển đổi dẫn đến
1, điều này sẽ đảm bảo sự bình đẳng 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
==
6. Nếu chuyển đổi không thành công, hãy trả lại
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 thường không bằng nhau đối với ===
4 và ===
3. 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 Object.is[]
0 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ị ===
4. Bình đẳng lỏng lẻo là một trong những bối cảnh như vậy. Object.is[]
2 và Object.is[]
3 đánh giá là true nếu và chỉ khi A là một đối tượng mô phỏng ===
4. 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 ===
4 hoặc ===
3
Trong 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 phép so sánh đẳng thức lỏng lẻo liên quan đến số nguyên thủy Object.is[]
7, nguyên hàm bigint Object.is[]
8, nguyên hàm chuỗi Object.is[]
9 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à Object.is[]
9________số 8_______
Đẳng thức lỏng lẻo chỉ được sử dụng bởi toán tử ________ 272 _______
Đẳ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 nào được đưa 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 đợiTươ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
function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
Same-value-zero chỉ khác với bình đẳng 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 bình đẳng 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 Object.is[]
7. Đ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ư phương pháp 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ínhMọ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ụ, dấu bằng kép có thể được coi là phiên bản mở rộng của dấu bằng ba, bởi vì dấu bằng trước thực hiện mọi thứ mà dấu bằng 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 số bằng gấp đôi hoặc "chặt chẽ hơn" so với số bằng 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á 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
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 bộ ba bằng nhau thậm chí còn chặt chẽ hơn, 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. Tuy nhiên, 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 không đúng sự thật. 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 chặt chẽ của nó đối với các toán tử đẳng thứcxy==
===
console.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
}
28===
4===
4console.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===
3===
3console.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
}
31function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
0function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
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
}
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
}
31Object.is[]
7Object.is[]
7console.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
}
3Object.is[]
7console.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
}
2Object.is[]
7console.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
}
31Object.is[]
8console.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
}
31Object.is[]
7const 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
}
95Object.is[]
7console.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
}
69Object.is[]
9Object.is[]
7console.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
14console.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
19const 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
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
}
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
25console.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
}
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
}
69===
3===
4console.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
}
69===
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
0console.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
}
69===
4const 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
}
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
}
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
49const 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
49console.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
}
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
25const 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
25console.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
}
69Object.is[]
7===
3console.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
}
69Object.is[]
7console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN:
console.log["Surprise"]; // Nothing is logged
}
1console.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
}
69console.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
}
1console.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
}
69console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN:
console.log["Surprise"]; // Nothing is logged
}
1console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN:
console.log["Surprise"]; // Nothing is logged
}
1console.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
}
31console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN:
console.log["Surprise"]; // Nothing is logged
}
31Nó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 ===
. 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 với giá trị function sameValueZero[x, y] {
if [typeof x === "number" && typeof y === "number"] {
// x and y are equal [may be -0 and 0] or they are both NaN
return x === y || [x !== x && y !== y];
}
return x === y;
}
0, nhìn chung, việc phân biệt trường hợp đặc biệt của các kiểm tra 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 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 thể hiện 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 phương]Xem xét ví dụ sau
const stoppingForce = obj.mass * -obj.velocity;
Nế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à Object.is[]
7 [hoặc tính thành Object.is[]
7], thì 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 một ____11_______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 _____11_______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ũ âm, lẻ 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ể lấy 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 ____11_______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 ước tính 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 biểu 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á 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
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ốnĐặc tả
console.log[[NaN].indexOf[NaN]]; // -1
switch [NaN] {
case NaN:
console.log["Surprise"]; // Nothing is logged
}
06 xử lý 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 phẩy độ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ụ