ES6 - 算术运算符



假定变量 ab 的值分别为 10 和 5。

示例

var num1 = 10
var num2 = 2
var res = 0
res = num1+num2
console.log("Sum: "+ res);
res = num1-num2;
console.log("Difference: "+res)
res = num1*num2
console.log("Product: "+res)
res = num1/num2
console.log("Quotient: "+res)
res = num1%num2
console.log("Remainder: "+res)
num1++
console.log("Value of num1 after increment "+num1)
num2--
console.log("Value of num2 after decrement "+num2)

在上述程序成功执行后,将显示以下输出内容。

Sum: 12
Difference: 8
Product: 20
Quotient : 5
Remainder: 0
Value of num1 after increment: 11
Value of num2 after decrement: 1
广告