W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
關(guān)系運(yùn)算符測(cè)試或定義兩個(gè)實(shí)體之間的關(guān)系類型。關(guān)系運(yùn)算符返回一個(gè)Boolean值,即true/false。
假設(shè)A的值為10,B的值為20。
運(yùn)算符 | 描述 | 示例 |
---|---|---|
> | 大于 | (A> B)是 False |
< | 小于 | (A <B)是 True |
> = | 大于或等于 | (A> = B)是 False |
<= | 小于或等于 | (A <= B)是 True |
== | 等于 | (A == B)是 False |
!= | 不等于 | (A!= B)是 True |
var num1:number = 5;
var num2:number = 9;
console.log("Value of num1: "+num1);
console.log("Value of num2 :"+num2);
var res = num1>num2
console.log("num1 greater than num2: "+res)
res = num1<num2
console.log("num1 lesser than num2: "+res)
res = num1>=num2
console.log("num1 greater than or equal to num2: "+res)
res = num1<=num2
console.log("num1 lesser than or equal to num2: "+res)
res = num1==num2
console.log("num1 is equal to num2: "+res)
res = num1!=num2
console.log("num1 is not equal to num2: "+res)
在編譯時(shí),它將生成以下JavaScript代碼:
var num1 = 5;
var num2 = 9;
console.log("Value of num1: " + num1);
console.log("Value of num2 :" + num2);
var res = num1 > num2;
console.log("num1 greater than num2: " + res);
res = num1 < num2;
console.log("num1 lesser than num2: " + res);
res = num1 >= num2;
console.log("num1 greater than or equal to num2: " + res);
res = num1 <= num2;
console.log("num1 lesser than or equal to num2: " + res);
res = num1 == num2;
console.log("num1 is equal to num2: " + res);
res = num1 != num2;
console.log("num1 not equal to num2: " + res);
它將產(chǎn)生以下輸出:
Value of num1: 5
Value of num2 :9
num1 greater than num2: false
num1 lesser than num2: true
num1 greater than or equal to num2: false
num1 lesser than or equal to num2: true
14 num1 is equal to num2: false
16 num1 not equal to num2: true
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)系方式:
更多建議: