Nhà điều hành là gì?
Trong JavaScript, toán tử là một biểu tượng đặc biệt được sử dụng để thực hiện các hoạt động trên toán hạng [giá trị và biến]. Ví dụ,
2 + 3; // 5
Ở đây
const x = 5;
1 là một nhà điều hành thực hiện bổ sung và const x = 5;
2 và const x = 5;
3 là các toán hạng.Các loại toán tử JavaScript
Dưới đây là danh sách các nhà khai thác khác nhau mà bạn sẽ học trong hướng dẫn này.
- Toán tử chuyển nhượng
- Toán tử số học
- Toán tử so sánh
- Toán tử logic
- Các nhà khai thác bitwise
- Toán tử chuỗi
- Các nhà khai thác khác
Các toán tử gán JavaScript
Các toán tử gán được sử dụng để gán các giá trị cho các biến. Ví dụ,assign values to variables. For example,
const x = 5;
Ở đây, toán tử
const x = 5;
4 được sử dụng để gán giá trị const x = 5;
5 cho biến const x = 5;
6.Dưới đây là danh sách các toán tử gán thường được sử dụng:
4 | Toán tử chuyển nhượng | 8 |
9 | Bổ sung nhiệm vụ | 0 |
1 | Phép trừ phân công | 2 |
3 | Bài tập nhân | 4 |
5 | Phân chia phân công | 6 |
7 | Phần còn lại | 8 |
9 | Phân công số mũ | 0 |
Lưu ý: Toán tử gán thường được sử dụng là
4. Bạn sẽ hiểu các toán tử phân công khác như const x = 5;
9, const x = 5;
1, const number = 3 + 5; // 8
3, v.v ... Một khi chúng ta học các toán tử số học. The commonly used assignment operator is const number = 3 + 5; // 8
const x = 5;
4. You will understand other assignment operators such as const x = 5;
9, const number = 3 + 5; // 8
1, const number = 3 + 5; // 8
3 etc. once we learn arithmetic operators.Các toán tử số học JavaScript
Các toán tử số học được sử dụng để thực hiện tính toán số học. Ví dụ,arithmetic calculations. For example,
const number = 3 + 5; // 8
Ở đây, toán tử
const x = 5;
1 được sử dụng để thêm hai toán hạng.
4 | Toán tử chuyển nhượng | 8 |
9 | Bổ sung nhiệm vụ | 0 |
1 | Phép trừ phân công | 2 |
3 | Bài tập nhân | 4 |
5 | Phân chia phân công | 6 |
7 | Phần còn lại | 8 |
9 | Phân công số mũ | 0 |
Lưu ý: Toán tử gán thường được sử dụng là 4. Bạn sẽ hiểu các toán tử phân công khác như 9, 1, 3, v.v ... Một khi chúng ta học các toán tử số học. | Các toán tử số học JavaScript | Các toán tử số học được sử dụng để thực hiện tính toán số học. Ví dụ, |
Ở đây, toán tử const x = 5;
1 được sử dụng để thêm hai toán hạng.
const x = 5;
let x = 5;
let y = 3;
// addition
console.log['x + y = ', x + y]; // 8
// subtraction
console.log['x - y = ', x - y]; // 2
// multiplication
console.log['x * y = ', x * y]; // 15
// division
console.log['x / y = ', x / y]; // 1.6666666666666667
// remainder
console.log['x % y = ', x % y]; // 2
// increment
console.log['++x = ', ++x]; // x is now 6
console.log['x++ = ', x++]; // prints 6 and then increased to 7
console.log['x = ', x]; // 7
// decrement
console.log['--x = ', --x]; // x is now 6
console.log['x-- = ', x--]; // prints 6 and then decreased to 5
console.log['x = ', x]; // 5
//exponentiation
console.log['x ** y =', x ** y];
const x = 5;
1Phép cộng: The
// equal operator
console.log[2 == 2]; // true
console.log[2 == '2']; // true
// not equal operator
console.log[3 != 2]; // true
console.log['hello' != 'Hello']; // true
// strict equal operator
console.log[2 === 2]; // true
console.log[2 === '2']; // false
// strict not equal operator
console.log[2 !== '2']; // true
console.log[2 !== 2]; // false
2 operator was introduced in ECMAScript 2016 and some browsers may not support them. To learn more, visit JavaScript
exponentiation browser support.let x = 5;
let y = 3;
// addition
console.log['x + y = ', x + y]; // 8
// subtraction
console.log['x - y = ', x - y]; // 2
// multiplication
console.log['x * y = ', x * y]; // 15
// division
console.log['x / y = ', x / y]; // 1.6666666666666667
// remainder
console.log['x % y = ', x % y]; // 2
// increment
console.log['++x = ', ++x]; // x is now 6
console.log['x++ = ', x++]; // prints 6 and then increased to 7
console.log['x = ', x]; // 7
// decrement
console.log['--x = ', --x]; // x is now 6
console.log['x-- = ', x--]; // prints 6 and then decreased to 5
console.log['x = ', x]; // 5
//exponentiation
console.log['x ** y =', x ** y];
7
let x = 5;
let y = 3;
// addition
console.log['x + y = ', x + y]; // 8
// subtraction
console.log['x - y = ', x - y]; // 2
// multiplication
console.log['x * y = ', x * y]; // 15
// division
console.log['x / y = ', x / y]; // 1.6666666666666667
// remainder
console.log['x % y = ', x % y]; // 2
// increment
console.log['++x = ', ++x]; // x is now 6
console.log['x++ = ', x++]; // prints 6 and then increased to 7
console.log['x = ', x]; // 7
// decrement
console.log['--x = ', --x]; // x is now 6
console.log['x-- = ', x--]; // prints 6 and then decreased to 5
console.log['x = ', x]; // 5
//exponentiation
console.log['x ** y =', x ** y];
let x = 5;
let y = 3;
// addition
console.log['x + y = ', x + y]; // 8
// subtraction
console.log['x - y = ', x - y]; // 2
// multiplication
console.log['x * y = ', x * y]; // 15
// division
console.log['x / y = ', x / y]; // 1.6666666666666667
// remainder
console.log['x % y = ', x % y]; // 2
// increment
console.log['++x = ', ++x]; // x is now 6
console.log['x++ = ', x++]; // prints 6 and then increased to 7
console.log['x = ', x]; // 7
// decrement
console.log['--x = ', --x]; // x is now 6
console.log['x-- = ', x--]; // prints 6 and then decreased to 5
console.log['x = ', x]; // 5
//exponentiation
console.log['x ** y =', x ** y];
8compare two values and return a boolean value, either // equal operator
console.log[2 == 2]; // true
console.log[2 == '2']; // true
// not equal operator
console.log[3 != 2]; // true
console.log['hello' != 'Hello']; // true
// strict equal operator
console.log[2 === 2]; // true
console.log[2 === '2']; // false
// strict not equal operator
console.log[2 !== '2']; // true
console.log[2 !== 2]; // false
5 or // equal operator
console.log[2 == 2]; // true
console.log[2 == '2']; // true
// not equal operator
console.log[3 != 2]; // true
console.log['hello' != 'Hello']; // true
// strict equal operator
console.log[2 === 2]; // true
console.log[2 === '2']; // false
// strict not equal operator
console.log[2 !== '2']; // true
console.log[2 !== 2]; // false
6. For example,const a = 3, b = 2;
console.log[a > b]; // true
Phép trừ
4 | Toán tử chuyển nhượng: returns 5 if the operands are equal
| 8 |
9 | Bổ sung nhiệm vụ: returns 5 if the operands are not equal
| 0 |
1 | Phép trừ phân công: 5 if the operands are equal and of the same type
| 2 |
3 | Bài tập nhân: 5 if the operands are equal but of different type or not equal at all
| 4 |
5 | Phân chia phân công: 5 if left operand is greater than the right operand
| 6 |
7 | Phần còn lại: 5 if left operand is greater than or equal to the right operand
| 8 |
9 | Phân công số mũ: 5 if the left operand is less than the right operand
| 0 |
Lưu ý: Toán tử gán thường được sử dụng là 4. Bạn sẽ hiểu các toán tử phân công khác như 9, 1, 3, v.v ... Một khi chúng ta học các toán tử số học. | Các toán tử số học JavaScript: 5 if the left operand is less than or equal to the right operand
| Các toán tử số học được sử dụng để thực hiện tính toán số học. Ví dụ, |
Ở đây, toán tử const x = 5;
1 được sử dụng để thêm hai toán hạng.
const x = 5;
// equal operator
console.log[2 == 2]; // true
console.log[2 == '2']; // true
// not equal operator
console.log[3 != 2]; // true
console.log['hello' != 'Hello']; // true
// strict equal operator
console.log[2 === 2]; // true
console.log[2 === '2']; // false
// strict not equal operator
console.log[2 !== '2']; // true
console.log[2 !== 2]; // false
const x = 5;
1Phép cộng
let x = 5;
let y = 3;
// addition
console.log['x + y = ', x + y]; // 8
// subtraction
console.log['x - y = ', x - y]; // 2
// multiplication
console.log['x * y = ', x * y]; // 15
// division
console.log['x / y = ', x / y]; // 1.6666666666666667
// remainder
console.log['x % y = ', x % y]; // 2
// increment
console.log['++x = ', ++x]; // x is now 6
console.log['x++ = ', x++]; // prints 6 and then increased to 7
console.log['x = ', x]; // 7
// decrement
console.log['--x = ', --x]; // x is now 6
console.log['x-- = ', x--]; // prints 6 and then decreased to 5
console.log['x = ', x]; // 5
//exponentiation
console.log['x ** y =', x ** y];
7const x = 5, y = 3;
[x < 6] && [y < 5]; // true
let x = 5;
let y = 3;
// addition
console.log['x + y = ', x + y]; // 8
// subtraction
console.log['x - y = ', x - y]; // 2
// multiplication
console.log['x * y = ', x * y]; // 15
// division
console.log['x / y = ', x / y]; // 1.6666666666666667
// remainder
console.log['x % y = ', x % y]; // 2
// increment
console.log['++x = ', ++x]; // x is now 6
console.log['x++ = ', x++]; // prints 6 and then increased to 7
console.log['x = ', x]; // 7
// decrement
console.log['--x = ', --x]; // x is now 6
console.log['x-- = ', x--]; // prints 6 and then decreased to 5
console.log['x = ', x]; // 5
//exponentiation
console.log['x ** y =', x ** y];
8AND. Since both
true false true false5 and
true false true false6 are
// equal operator
console.log[2 == 2]; // true
console.log[2 == '2']; // true
// not equal operator
console.log[3 != 2]; // true
console.log['hello' != 'Hello']; // true
// strict equal operator
console.log[2 === 2]; // true
console.log[2 === '2']; // false
// strict not equal operator
console.log[2 !== '2']; // true
console.log[2 !== 2]; // false
5, the result is // equal operator
console.log[2 == 2]; // true
console.log[2 == '2']; // true
// not equal operator
console.log[3 != 2]; // true
console.log['hello' != 'Hello']; // true
// strict equal operator
console.log[2 === 2]; // true
console.log[2 === '2']; // false
// strict not equal operator
console.log[2 !== '2']; // true
console.log[2 !== 2]; // false
5.
4 | Toán tử chuyển nhượng: 5 if both the operands are 5, else returns 6
| 8 |
9 | Bổ sung nhiệm vụ: 5 if either of the operands is 5; returns false if both are 6
| 0 |
1 | Phép trừ phân công: 5 if the operand is 6 and vice-versa.
| 2 |
const number = 3 + 5; // 8
3
const number = 3 + 5; // 8
// logical AND
console.log[true && true]; // true
console.log[true && false]; // false
// logical OR
console.log[true || false]; // true
// logical NOT
console.log[!true]; // false
Bài tập nhân
true false true false
const number = 3 + 5; // 8
4const number = 3 + 5; // 8
5
const number = 3 + 5; // 8
Phân chia phân công
Thí dụ | 4 |
Toán tử chuyển nhượng | 8 |
9 | Bổ sung nhiệm vụ |
0 | 1 |
Phép trừ phân công | 2 |
3 | Bài tập nhân |
4 | 5 |
Phân chia phân công
Toán tử chuỗi JavaScript
Trong JavaScript, bạn cũng có thể sử dụng toán tử
const x = 5;
1 để kết hợp [tham gia] hai hoặc nhiều chuỗi.Ví dụ 4: Toán tử chuỗi trong JavaScript
// concatenation operator
console.log['hello' + 'world'];
let a = 'JavaScript';
a += ' tutorial'; // a = a + ' tutorial';
console.log[a];
Đầu ra
const x = 5;
0Lưu ý: Khi
1 được sử dụng với các chuỗi, nó thực hiện kết nối. Tuy nhiên, khi const x = 5;
1 được sử dụng với các số, nó thực hiện bổ sung. When const x = 5;
const x = 5;
1 is used with strings, it performs concatenation. However, when const x = 5;
1 is used with numbers, it performs addition.Các toán tử JavaScript khác
Dưới đây là danh sách các nhà khai thác khác có sẵn trong JavaScript. Bạn sẽ tìm hiểu về các nhà khai thác này trong các hướng dẫn sau này.
13 | Đánh giá nhiều toán hạng và trả về giá trị của toán hạng cuối cùng. | 14 |
15 | Trả về giá trị dựa trên điều kiện | 16 |
17 | Xóa thuộc tính của một đối tượng hoặc một phần tử của một mảng | 18 |
19 | Trả về một chuỗi cho biết kiểu dữ liệu | 20 |
21 | loại bỏ giá trị trả về của biểu thức | 22 |
23 | Trả về 5 nếu thuộc tính được chỉ định nằm trong đối tượng | 25 |
26 | Trả về 5 nếu đối tượng được chỉ định thuộc loại đối tượng được chỉ định | 28 |