关系运算符测试或定义两个实体之间的关系类型。关系运算符返回一个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
环境声明是一种告诉TypeScript编译器实际源代码存在于其他位置的方法。当你使用像jquery/angularjs/nodejs这样的第三方js库时,...
TypeScript 字符串toString()方法toString()方法返回表示指定对象的字符串。语法string.toString( )返回值返回表示指定对象的字...
一个对象是包含一组键值对集合的实例。值可以是标量值或函数,甚至是其他对象的数组。语法如下所示:语法var object_name = {key...
let和const是JavaScript里相对较新的变量声明方式。 像我们之前提到过的,let在很多方面与var是相似的,但是可以帮助大家避免在J...
在 Ruby 中使用 JSON本教程将会教我们如何使用 Ruby 编程语言编码和解码 JSON。让我们先来准备环境以便针对 JSON 进行 Ruby 编程...