举报投诉联系我们 手机版 热门标签 鳄鱼CMS
您的位置:鳄鱼CMS > TypeScript 关系运算符示例

TypeScript 关系运算符示例

2023-04-22 19:31 TypeScript教程

 TypeScript 关系运算符示例

TypeScript  关系运算符示例

关系运算符测试或定义两个实体之间的关系类型。关系运算符返回一个Boolean值,即true/false。

假设A的值为10,B的值为20。

运算符描述示例
>大于(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)

在编译时,它将生成以下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);

它将产生以下输出:

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
阅读全文
以上是鳄鱼CMS为你收集整理的 TypeScript 关系运算符示例全部内容。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
相关文章
© 2024 鳄鱼CMS eyucms.com 版权所有 联系我们