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.<=Returns a boolean value true if the left-side value is less than or equal to the right-side value; otherwise, returns false.

Ví dụ sau minh họa các toán tử so sánh

Ví dụ. Toán tử so sánh JavaScript

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

Thử nó

Toán tử logic

Trong JavaScript, các toán tử logic được sử dụng để kết hợp hai hoặc nhiều điều kiện. JavaScript cung cấp các toán tử logic sau

Toán tửMô tả&&&& được gọi là toán tử AND. Nó kiểm tra xem hai toán hạng có khác 0 hay không (0, false, undefined, null hoặc "" được coi là 0). Nó trả về 1 nếu chúng khác không; . được gọi là toán tử OR. Nó kiểm tra xem bất kỳ một trong hai toán hạng có khác 0 hay không (0, false, undefined, null hoặc "" được coi là 0). Nó trả về 1 nếu bất kỳ một trong số chúng khác không; . được gọi là toán tử NOT. Nó đảo ngược kết quả boolean của toán hạng (hoặc điều kiện).

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
02 trả 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
00 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
04 trả 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
01

Ví dụ. Toán tử logic

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
8

Thử nó

Toán tử gán

JavaScript cung cấp các toán tử gán để gán giá trị cho các biến với ít thao tác gõ phím hơn

Toán tử gánDescription=Gán giá trị toán hạng bên phải cho toán hạng bên trái. +=Tính tổng các giá trị toán hạng bên trái và bên phải và gán kết quả cho toán hạng bên trái. -=Trừ giá trị toán hạng bên phải từ giá trị toán hạng bên trái và gán kết quả cho toán hạng bên trái. *=Nhân các giá trị toán hạng trái và phải và gán kết quả cho toán hạng trái. /=Chia giá trị toán hạng bên trái cho giá trị toán hạng bên phải và gán kết quả cho toán hạng bên trái. %=Lấy mô đun của toán hạng bên trái chia cho toán hạng bên phải và gán mô đun kết quả cho toán hạng bên trái

Ví dụ. Toán tử gán

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
9

Thử nó

Toán tử bậc ba

JavaScript cung cấp một toán tử đặc biệt có tên là toán tử bậc ba

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
06 gán giá trị cho một biến dựa trên một số điều kiện. Đây là dạng rút gọn của điều kiện if other

cú pháp

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

Toán tử bậc ba bắt đầu bằng biểu thức điều kiện theo sau là 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
07. Phần thứ hai (sau
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
07 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
09) sẽ được thực hiện nếu điều kiện trở thành đúng. Giả sử, điều kiện trả 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
01, thì phần thứ ba (sau. ) sẽ được thực hiện

Là gì. = bằng JavaScript?

Phép gán logic OR ( x. = y ) toán tử chỉ gán nếu x sai

&& là gì và. trong JS?

Các logic và ( && ) và hoặc (. ) là toán tử logic trong JavaScript. Thông thường, bạn đang sử dụng các toán tử này trên booleans. đúng && đúng // => đú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.