Có += hoặc =+ trong JavaScript không?

JavaScript bao gồm các toán tử giống như các ngôn ngữ khác. Toán tử thực hiện một số thao tác trên một hoặc nhiều toán hạng [giá trị dữ liệu] và tạo ra kết quả. Ví dụ, trong

let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
6, dấu
let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
7 là một toán tử và 1 là toán hạng bên trái và 2 là toán hạng bên phải. Toán tử
let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
7 thực hiện phép cộng hai giá trị số và trả về kết quả

JavaScript bao gồm các danh mục toán tử sau

  1. toán tử số học
  2. Toán tử so sánh
  3. Toán tử logic
  4. Toán tử gán
  5. Toán tử có điều kiện
  6. Toán tử bậc ba

toán tử số học

Các toán tử số học được sử dụng để thực hiện các phép toán giữa các toán hạng số

Toán tửMô tả+Thêm hai toán hạng số. -Trừ toán hạng bên phải từ toán hạng bên trái*Nhân hai toán hạng số. /Chia toán hạng bên trái cho toán hạng bên phải. Toán tử %mô-đun. Trả về phần còn lại của hai toán hạng. ++ Toán tử gia tăng. Tăng giá trị toán hạng lên một. --Decrement toán tử. Giảm giá trị đi một

Ví dụ sau minh họa cách toán tử số học thực hiện các tác vụ khác nhau trên toán hạng

Ví dụ. Phép toán số học

let x = 5, y = 10;

let z = x + y; //performs addition and returns 15

z = y - x; //performs subtraction and returns 5

z = x * y; //performs multiplication and returns 50

z = y / x; //performs division and returns 2

z = x % 2; //returns division remainder 1

Thử nó

Toán tử

let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
1 và
let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
2 là toán tử một ngôi. Nó chỉ hoạt động với toán hạng trái hoặc phải. Khi được sử dụng với toán hạng bên trái, e. g. ,
let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
3, nó sẽ tăng giá trị của
let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
4 khi điều khiển chương trình chuyển sang câu lệnh tiếp theo. Theo cách tương tự, khi nó được sử dụng với toán hạng bên phải, e. g. ,
let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
5, nó sẽ tăng giá trị của
let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
4 thôi. Do đó,
let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
3 được gọi là tăng sau và
let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
5 được gọi là tăng trước

Ví dụ. Tăng/giảm sau và trước

let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here

Thử nó

nối chuỗi

Toán tử

let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
7 thực hiện thao tác nối khi một trong các toán hạng có kiểu chuỗi. Ví dụ sau minh họa nối chuỗi ngay cả khi một trong các toán hạng là một chuỗi

Ví dụ. + Toán Tử Với Chuỗi

let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
0

Thử nó

Toán tử so sánh

JavaScript cung cấp các toán tử so sánh để so sánh hai toán hạng và trả về giá trị boolean

let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
00 hoặc
let x = 5;

x++; //post-increment, x will be 5 here and 6 in the next line

++x; //pre-increment, x will be 7 here  

x--; //post-decrement, x will be 7 here and 6 in the next line

--x; //pre-decrement, x will be 5 here
01

OperatorsDescription==Compares the equality of two operands without considering type.===Compares equality of two operands with type.!=Compares inequality of two operands.>Returns a boolean value true if the left-side value is greater than the right-side value; otherwise, returns false.=Returns a boolean value true if the left-side value is greater than or equal to the right-side value; otherwise, returns false. đúng. đúng && sai // => sai.

Bạn có thể sử dụng. trong JavaScript?

Hợp logic OR [. ] toán tử và nếu. câu lệnh khác trong JavaScript. Trong logic OR [. ], nếu một hoặc cả hai điều kiện đều đúng thì mã bên trong câu lệnh if sẽ thực thi .

Có += hoặc =+ trong JavaScript không?

cú pháp đúng là a+=b; . nó chỉ đơn giản là gán giá trị b cho a. . it is simply assigning b value to a.

Chủ Đề