W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
假設(shè)變量a和b中的值分別為10和5。
運(yùn)算符 | 描述 | 示例 |
---|---|---|
+(加法) | 返回操作數(shù)的總和 | a + b = 15 |
-(減法) | 返回值的差 | a - b = 5 |
*(乘法) | 返回值的乘積 | a * b = 50 |
/(除法) | 執(zhí)行除法運(yùn)算并返回商 | a / b = 2 |
%(取余) | 執(zhí)行除法并返回余數(shù) | a%b = 0 |
++(遞增) | 將變量的值增加1 | a ++ = 11 |
--(遞減) | 將變量的值減少1 | a-- = 9 |
var num1:number = 10
var num2:number = 2
var res:number = 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)
在編譯時(shí),它將生成以下的JavaScript代碼:
//Generated by typescript 1.8.10
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
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: