Hướng dẫn explain different arithmetic operators in javascript - giải thích các toán tử số học khác nhau trong javascript

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:

Nhà điều hànhTênThí dụ
const x = 5;
4
Toán tử chuyển nhượng
const x = 5;
8
const x = 5;
9
Bổ sung nhiệm vụ
const number = 3 + 5; // 8
0
const number = 3 + 5; // 8
1
Phép trừ phân công
const number = 3 + 5; // 8
2
const number = 3 + 5; // 8
3
Bài tập nhân
const number = 3 + 5; // 8
4
const number = 3 + 5; // 8
5
Phân chia phân công
const number = 3 + 5; // 8
6
const number = 3 + 5; // 8
7
Phần còn lại
const number = 3 + 5; // 8
8
const number = 3 + 5; // 8
9
Phân công số mũ
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);
0

Lưu ý: Toán tử gán thường được sử dụng là

const x = 5;
4. Bạn sẽ hiểu các toán tử phân công khác như
const x = 5;
9,
const number = 3 + 5; // 8
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 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.

Nhà điều hànhTênThí dụ
const x = 5;
4
Toán tử chuyển nhượng
const x = 5;
8
const x = 5;
9
Bổ sung nhiệm vụ
const number = 3 + 5; // 8
0
const number = 3 + 5; // 8
1
Phép trừ phân công
const number = 3 + 5; // 8
2
const number = 3 + 5; // 8
3
Bài tập nhân
const number = 3 + 5; // 8
4
const number = 3 + 5; // 8
5
Phân chia phân công
const number = 3 + 5; // 8
6
const number = 3 + 5; // 8
7
Phần còn lại
const number = 3 + 5; // 8
8
const number = 3 + 5; // 8
9
Phân công số mũ
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);
0
Lưu ý: Toán tử gán thường được sử dụng là
const x = 5;
4. Bạn sẽ hiểu các toán tử phân công khác như
const x = 5;
9,
const number = 3 + 5; // 8
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.
Các toán tử số học JavaScriptCá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.

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;
1

Phé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);
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ừ

Nhà điều hànhTênThí dụ
const x = 5;
4
Toán tử chuyển nhượng: returns
// 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 if the operands are equal
const x = 5;
8
const x = 5;
9
Bổ sung nhiệm vụ: returns
// 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 if the operands are not equal
const number = 3 + 5; // 8
0
const number = 3 + 5; // 8
1
Phép trừ phân công:
// 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 if the operands are equal and of the same type
const number = 3 + 5; // 8
2
const number = 3 + 5; // 8
3
Bài tập nhân:
// 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 if the operands are equal but of different type or not equal at all
const number = 3 + 5; // 8
4
const number = 3 + 5; // 8
5
Phân chia phân công:
// 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 if left operand is greater than the right operand
const number = 3 + 5; // 8
6
const number = 3 + 5; // 8
7
Phần còn lại:
// 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 if left operand is greater than or equal to the right operand
const number = 3 + 5; // 8
8
const number = 3 + 5; // 8
9
Phân công số mũ:
// 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 if the left operand is less than the right operand
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);
0
Lưu ý: Toán tử gán thường được sử dụng là
const x = 5;
4. Bạn sẽ hiểu các toán tử phân công khác như
const x = 5;
9,
const number = 3 + 5; // 8
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.
Các toán tử số học JavaScript:
// 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 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.

// 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;
1


Phé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);
7

const 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
false
5 and
true
false
true
false
6 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.

Nhà điều hànhTênThí dụ
const x = 5;
4
Toán tử chuyển nhượng:
// 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 if both the operands 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, else returns
// 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
const x = 5;
8
const x = 5;
9
Bổ sung nhiệm vụ:
// 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 if either of the operands 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; returns false if both 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
6
const number = 3 + 5; // 8
0
const number = 3 + 5; // 8
1
Phép trừ phân công:
// 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 if the operand 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
6 and vice-versa.
const number = 3 + 5; // 8
2


const number = 3 + 5; // 83

// 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
4


const number = 3 + 5; // 85

Phân chia phân công

Nhà điều hànhTên
Thí dụ
const x = 5;
4
Toán tử chuyển nhượng
const x = 5;
8
const x = 5;
9
Bổ sung nhiệm vụ
const number = 3 + 5; // 8
0
const number = 3 + 5; // 8
1
Phép trừ phân công
const number = 3 + 5; // 8
2
const number = 3 + 5; // 8
3
Bài tập nhân
const number = 3 + 5; // 8
4
const number = 3 + 5; // 8
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;
0

Lưu ý: Khi

const x = 5;
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;
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.

Nhà điều hànhSự mô tảThí dụ
const x = 5;
13
Đánh giá nhiều toán hạng và trả về giá trị của toán hạng cuối cùng.
const x = 5;
14
const x = 5;
15
Trả về giá trị dựa trên điều kiện
const x = 5;
16
const x = 5;
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
const x = 5;
18
const x = 5;
19
Trả về một chuỗi cho biết kiểu dữ liệu
const x = 5;
20
const x = 5;
21
loại bỏ giá trị trả về của biểu thức
const x = 5;
22
const x = 5;
23
Trả về
// 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 nếu thuộc tính được chỉ định nằm trong đối tượng
const x = 5;
25
const x = 5;
26
Trả về
// 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 nếu đối tượng được chỉ định thuộc loại đối tượng được chỉ định
const x = 5;
28

Các toán tử số học trong JavaScript là gì?

Toán tử số học.

Các loại toán tử số học khác nhau là gì?

Sự định nghĩa.Các toán tử số học thực hiện các hoạt động bổ sung, trừ, nhân, chia, số mũ và mô đun.addition, subtraction, multiplication, division, exponentiation, and modulus operations.

7 toán tử số học là gì?

Các toán tử số học được sử dụng để thực hiện các hoạt động toán học như bổ sung, trừ, nhân và chia ...
Addition..
Subtraction..
Multiplication..
Division..
Modulus..
Exponentiation..
Phân chia sàn ..

4 toán tử số học là gì?

Bốn hoạt động số học cơ bản trong toán học, cho tất cả các số thực, là:..
Ngoài ra (tìm tổng; '+').
Phép trừ (tìm sự khác biệt; '-').
Phép nhân (tìm sản phẩm; '×').
Phân chia (tìm kiếm thương số; '÷').

5 toán tử số học cơ bản là gì?

Các toán tử này là + (bổ sung), - (phép trừ), * (phép nhân), / (chia) và % (modulo).+ (addition), - (subtraction), * (multiplication), / (division), and % (modulo).

Có bao nhiêu loại toán tử trong JavaScript?

Các nhà khai thác JavaScript phong phú như những gì bạn mong đợi từ bất kỳ ngôn ngữ hiện đại nào.Có bốn loại: số học, so sánh, gán và logic.four categories: arithmetic, comparison, assignment, and logical.