我使用JSLint通过JavaScript,它返回了许多建议,以取代 ==(两个平等的标志)与 ===(三个平等的标志)当做一些事情,如比较idSele_UNVEHtype.value.length == 0在一个假设声明。
能否取代 = = = = = = =?
任何性能改进都将被欢迎,因为有许多比较运营商。
如果没有类型转换发生,会有超越 ==的性能收益吗?
我使用JSLint通过JavaScript,它返回了许多建议,以取代 ==(两个平等的标志)与 ===(三个平等的标志)当做一些事情,如比较idSele_UNVEHtype.value.length == 0在一个假设声明。
能否取代 = = = = = = =?
任何性能改进都将被欢迎,因为有许多比较运营商。
如果没有类型转换发生,会有超越 ==的性能收益吗?
当前回答
意思是平等 没有类型强制性 类型强制性 意思是 JavaScript 不会自动将任何其他数据类型转换为序列数据类型
0==false // true,although they are different types
0===false // false,as they are different types
2=='2' //true,different types,one is string and another is integer but
javaScript convert 2 to string by using == operator
2==='2' //false because by using === operator ,javaScript do not convert
integer to string
2===2 //true because both have same value and same types
其他回答
不同之間的 =, =, = =
= 操作员 只用来指定值 = = 操作员 只用来比较不数据型值 = = 操作员 只用来比较值和数据型值。
操作员称为严格的比较操作员,与操作员不同。
将采取2 vars a 和 b。
对于“a = = b”来评估为真实的 a 和 b 必须是相同的值。
在“a === b”的情况下,a 和 b 必须是相同的值,也必须是相同的类型,以便它被评估为真实。
接下来的例子
var a = 1;
var b = "1";
if (a == b) //evaluates to true as a and b are both 1
{
alert("a == b");
}
if (a === b) //evaluates to false as a is not the same type as b
{
alert("a === b");
}
简而言之,使用 == 操作员可能会在您不希望使用 === 操作员这样做的情况下评估为真实。
在90%的使用场景中,不管你使用哪个,但当你有一天得到一些意想不到的行为时,知道差异是有用的。
操作员只是比较不数据类的值。
=== 运营商将值与其数据类型的比较进行比较。
艾:
1 == "1" //true
1 === "1" //false
此操作员(“===”)用于自动输入字符的语言,例如 PHP,JavaScript。
=== 运营商检查值以及变量的类型,以便平等。
操作员只检查平等变量的值。
使用 === 如果你想在JavaScript中比较几件事,它被称为严格的平等,这意味着如果只有两种类型和值是相同的,就不会有任何不需要的类型纠正为你,如果你使用 ==,你基本上不关心类型,在许多情况下你可能会遇到问题与空虚的平等比较。
使用严格的平等 ===
var num = 0;
var obj = new String('0');
var str = '0';
console.log(num === num); // true
console.log(obj === obj); // true
console.log(str === str); // true
console.log(num === obj); // false
console.log(num === str); // false
console.log(obj === str); // false
console.log(null === undefined); // false
console.log(obj === null); // false
console.log(obj === undefined); // false
使用平等 = = =
空的平等比较两种平等值,然后将两种值转换为一个常见的类型。 转换后(一方或两方可能遭受转换),最终的平等比较按 === 进行。 空的平等是相同的: A == B 总是具有相同的序列为 B == A 的任何值 A 和 B (除了应用转换顺序)。
var num = 0;
var obj = new String('0');
var str = '0';
console.log(num == num); // true
console.log(obj == obj); // true
console.log(str == str); // true
console.log(num == obj); // true
console.log(num == str); // true
console.log(obj == str); // true
console.log(null == undefined); // true
// both false, except in rare cases
console.log(obj == null);
console.log(obj == undefined);