Hướng dẫn describe the logical operators in javascript with the help of example - mô tả các toán tử logic trong javascript với sự trợ giúp của ví dụ

Các toán tử so sánh JavaScript

Các toán tử so sánh so sánh hai giá trị và trả lại giá trị boolean:

const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 hoặc
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2. Các nhà khai thác so sánh được sử dụng trong việc ra quyết định và vòng lặp.

Nhà điều hànhSự mô tảThí dụ
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
3
Bằng:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu các toán hạng bằng nhau
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if the operands are equal
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
5
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
6
Không bằng:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu các toán hạng không bằng
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if the operands are not equal
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
8
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
9
Nghiêm ngặt bằng:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu các toán hạng bằng nhau và cùng loại
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if the operands are equal and of the same type
const a = 2;

// strict equal operator
console.log(a === 2); // true
console.log(a === '2'); // false
1
const a = 2;

// strict equal operator
console.log(a === 2); // true
console.log(a === '2'); // false
2
Nghiêm ngặt không bằng:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu các toán hạng bằng nhau nhưng thuộc loại khác nhau hoặc không bằng
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if the operands are equal but of different type or not equal at all
const a = 2;

// strict equal operator
console.log(a === 2); // true
console.log(a === '2'); // false
4
const a = 2;

// strict equal operator
console.log(a === 2); // true
console.log(a === '2'); // false
5
Lớn hơn:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 Nếu toán hạng bên trái lớn hơn toán hạng bên phải
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if the left operand is greater than the right operand
const a = 2;

// strict equal operator
console.log(a === 2); // true
console.log(a === '2'); // false
7
const a = 2;

// strict equal operator
console.log(a === 2); // true
console.log(a === '2'); // false
8
Lớn hơn hoặc bằng:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu toán hạng bên trái lớn hơn hoặc bằng với toán hạng bên phải
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if the left operand is greater than or equal to the right operand
 const a = 2, b = 'hello';

// strict not equal operator
console.log(a !== 2); // false
console.log(a !== '2'); // true
console.log(b !== 'Hello'); // true
0
 const a = 2, b = 'hello';

// strict not equal operator
console.log(a !== 2); // false
console.log(a !== '2'); // true
console.log(b !== 'Hello'); // true
1
Ít hơn:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu toán hạng bên trái nhỏ hơn toán hạng bên phải
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if the left operand is less than the right operand
 const a = 2, b = 'hello';

// strict not equal operator
console.log(a !== 2); // false
console.log(a !== '2'); // true
console.log(b !== 'Hello'); // true
3
 const a = 2, b = 'hello';

// strict not equal operator
console.log(a !== 2); // false
console.log(a !== '2'); // true
console.log(b !== 'Hello'); // true
4
Nhỏ hơn hoặc bằng:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu toán hạng bên trái nhỏ hơn hoặc bằng với toán hạng bên phải
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if the left operand is less than or equal to the right operand
 const a = 2, b = 'hello';

// strict not equal operator
console.log(a !== 2); // false
console.log(a !== '2'); // true
console.log(b !== 'Hello'); // true
6


Ví dụ 1: bằng người vận hành

const a = 5, b = 2, c = 'hello';

// equal to operator
console.log(a == 5);     // true
console.log(b == '2');   // true
console.log(c == 'Hello');  // false

const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
3 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu các toán hạng bằng nhau.

Lưu ý: Trong JavaScript,

const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
3 là toán tử so sánh, trong khi
const a = 3;

// greater than operator
console.log(a > 2); // true
0 là toán tử gán. Nếu bạn sử dụng nhầm
const a = 3;

// greater than operator
console.log(a > 2); // true
0 thay vì
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
3, bạn có thể nhận được kết quả không mong muốn.
: In JavaScript,
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
3 is a comparison operator, whereas
const a = 3;

// greater than operator
console.log(a > 2); // true
0 is an assignment operator. If you mistakenly use
const a = 3;

// greater than operator
console.log(a > 2); // true
0 instead of
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
3, you might get unwanted result.


Ví dụ 2: Không bằng người vận hành

const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true

const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
6 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu các toán hạng không bằng nhau.


Ví dụ 3: nghiêm ngặt bằng người vận hành

const a = 2;

// strict equal operator
console.log(a === 2); // true
console.log(a === '2'); // false

const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
9 đánh giá đến
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu các toán hạng bằng nhau và cùng loại. Ở đây 2 và '2' là cùng một số nhưng loại dữ liệu là khác nhau. Và
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
9 cũng kiểm tra kiểu dữ liệu trong khi so sánh.2 and '2' are the same numbers but the data type is different. And
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
9 also checks for the data type while comparing.


Lưu ý: Sự khác biệt giữa

const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
3 và
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
9 là:
: The difference between
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
3 and
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
9 is that:

const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
3 Đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 Nếu các toán hạng bằng nhau, tuy nhiên,
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
9 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 chỉ khi các toán hạng bằng nhau và cùng loại


Ví dụ 4: nghiêm ngặt không bằng người vận hành

 const a = 2, b = 'hello';

// strict not equal operator
console.log(a !== 2); // false
console.log(a !== '2'); // true
console.log(b !== 'Hello'); // true

const a = 2;

// strict equal operator
console.log(a === 2); // true
console.log(a === '2'); // false
2 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu các toán hạng hoàn toàn không bằng. Nó hoàn toàn trái ngược với hoàn toàn bằng
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
9.

Trong ví dụ trên,

const a = 3;

// greater than or equal operator
console.log(a >= 3); //true
7 đưa ra
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1. Đó là bởi vì các loại của chúng khác nhau mặc dù chúng có cùng giá trị.


Ví dụ 5: Lớn hơn toán tử

const a = 3;

// greater than operator
console.log(a > 2); // true

const a = 2;

// strict equal operator
console.log(a === 2); // true
console.log(a === '2'); // false
5 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu toán hạng bên trái lớn hơn toán hạng bên phải.


Ví dụ 6: Lớn hơn hoặc bằng người vận hành

const a = 3;

// greater than or equal operator
console.log(a >= 3); //true

const a = 2;

// strict equal operator
console.log(a === 2); // true
console.log(a === '2'); // false
8 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu toán hạng bên trái lớn hơn hoặc bằng với toán hạng bên phải.


Ví dụ 7: Ít hơn người vận hành

const a = 3, b = 2;

// less than operator
console.log(a < 2); // false
console.log(b < 3); // true

 const a = 2, b = 'hello';

// strict not equal operator
console.log(a !== 2); // false
console.log(a !== '2'); // true
console.log(b !== 'Hello'); // true
1 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu toán hạng bên trái nhỏ hơn toán hạng bên phải.


Ví dụ 8: Ít hơn hoặc bằng người vận hành

const a = 2;

// less than or equal operator
console.log(a <= 3) // true
console.log(a <= 2); // true

 const a = 2, b = 'hello';

// strict not equal operator
console.log(a !== 2); // false
console.log(a !== '2'); // true
console.log(b !== 'Hello'); // true
4 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu toán hạng bên trái nhỏ hơn hoặc bằng với toán hạng bên phải.


Toán tử logic JavaScript

Các toán tử logic thực hiện các hoạt động logic: và, hoặc không.AND, OR and NOT.

Nhà điều hànhSự mô tảThí dụ
const a = 3, b = 2;

// less than operator
console.log(a < 2); // false
console.log(b < 3); // true
7
Logic và:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 Nếu cả hai giá trị toán hạng/boolean là đúng, thì khác sẽ đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if both the operands/boolean values are true, else evaluates to
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2
const a = 2;

// less than or equal operator
console.log(a <= 3) // true
console.log(a <= 2); // true
0
const a = 2;

// less than or equal operator
console.log(a <= 3) // true
console.log(a <= 2); // true
1
Logic hoặc:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 Nếu một trong hai giá trị toán hạng/boolean là
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1. Đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2 nếu cả hai đều là
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if either of the operands/boolean values is
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1. evaluates to
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2 if both are
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2
const a = 2;

// less than or equal operator
console.log(a <= 3) // true
console.log(a <= 2); // true
6
const a = 2;

// less than or equal operator
console.log(a <= 3) // true
console.log(a <= 2); // true
7
Logic không:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 Nếu toán hạng là
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2 và ngược lại.
:
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 if the operand is
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2 and vice-versa.
const a = true, b = false;
const c = 4;

// logical AND
console.log(a && a); // true
console.log(a && b);  // false

console.log((c > 2) && (c < 2)); // false
0


Ví dụ 9: Logical và toán tử

const a = true, b = false;
const c = 4;

// logical AND
console.log(a && a); // true
console.log(a && b);  // false

console.log((c > 2) && (c < 2)); // false

const a = 3, b = 2;

// less than operator
console.log(a < 2); // false
console.log(b < 3); // true
7 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu cả hai toán hạng là
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1, khác sẽ đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2.

Lưu ý: Bạn cũng có thể sử dụng các toán tử logic với số. Trong JavaScript, 0 là

const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2 và tất cả các giá trị khác không là
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1.
You can also use logical operators with numbers. In JavaScript, 0 is
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2 and all non-zero values are
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1.


Ví dụ 10: logic hoặc toán tử

const a = true, b = false, c = 4;


// logical OR
console.log(a || b); // true
console.log(b || b); // false
console.log((c>2) || (c<2)); // true

const a = 2;

// less than or equal operator
console.log(a <= 3) // true
console.log(a <= 2); // true
1 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu một trong hai toán hạng là
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1. Nếu cả hai toán hạng là
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2, kết quả là
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2.


Ví dụ 11: Toán tử không phải logic

const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
0

const a = 2;

// less than or equal operator
console.log(a <= 3) // true
console.log(a <= 2); // true
7 đánh giá thành
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
1 nếu toán hạng là
const a = 3, b = 'hello';

// not equal operator
console.log(a != 2); // true
console.log(b != 'Hello'); // true
2 và ngược lại.

Các toán tử logic trong JavaScript là gì?

Toán tử logic.

Các toán tử logic mô tả với một ví dụ là gì?

Toán tử logic là một biểu tượng hoặc từ được sử dụng để kết nối hai hoặc nhiều biểu thức sao cho giá trị của biểu thức hợp chất được tạo ra chỉ phụ thuộc vào các biểu thức gốc và ý nghĩa của toán tử.Các toán tử logic phổ biến bao gồm và, hoặc, và không.

Các toán tử trong JavaScript giải thích với một ví dụ là gì?

Các toán tử số học JavaScript.

Có bao nhiêu toán tử logic trong JavaScript?

Có bốn toán tử logic trong JavaScript: ||(HOẶC VÀ), !(KHÔNG PHẢI), ??(Nullish Coalescing).four logical operators in JavaScript: || (OR), && (AND), ! (NOT), ?? (Nullish Coalescing).