当前位置: 首页 > 文档资料 > ES6 入门教程 >

Show 例子 1

优质
小牛编辑
126浏览
2023-12-01

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

例子 (Example)

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