运算符

算术运算符

加法运算符

1
2
3
4
5
// 加法运算符
let x = 10;
let y = 20;
let z = x + y;
console.log(z); // 30

减法运算符

1
2
3
4
5
// 减法运算符
let x = 10;
let y = 20;
let z = x - y;
console.log(z); // -10

乘法运算符

1
2
3
4
5
// 乘法运算符
let x = 10;
let y = 20;
let z = x * y;
console.log(z); // 200

除法运算符

1
2
3
4
5
// 除法运算符
let x = 10;
let y = 20;
let z = x / y;
console.log(z); // 0.5

余数运算符

1
2
3
4
5
// 余数运算符
let x = 10;
let y = 20;
let z = x % y;
console.log(z); // 10

自增运算符

1
2
3
4
5
// 自增运算符
let x = 10;
let y = x++;
console.log(x); // 11
console.log(y); // 10

自减运算符

1
2
3
4
5
// 自减运算符
let x = 10;
let y = x--;
console.log(x); // 9
console.log(y); // 10

逗号运算符

1
2
3
4
5
6
7
8
9
// 逗号运算符
let x = 10;
let y = 20;
let z = x + y,
a = 30,
b = 40;
console.log(z); // 30
console.log(a); // 30
console.log(b); // 40

赋值运算符

1
2
3
4
5
// 赋值运算符
let x = 10;
let y = 20;
x = y;
console.log(x); // 20