我使用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 

其他回答

平等比较:

运营商 =

回归是真实的,当两个操作员是平等的时,操作员在比较之前转换为相同的类型。

>>> 1 == 1
true
>>> 1 == 2
false
>>> 1 == '1'
true

平等与类型比较:

主持人 ===

回来是真实的,如果两个操作员是相同的和类型。 一般情况下,如果你比较这个方式,它是更好的和更安全的,因为没有背后的场景类型转换。

>>> 1 === '1'
false
>>> 1 === 1
true

不同之間的 =, =, = =

= 操作员 只用来指定值 = = 操作员 只用来比较不数据型值 = = 操作员 只用来比较值和数据型值。

意思是平等 没有类型强制性 类型强制性 意思是 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 

在典型的脚本中不会有性能差异 更重要的是,一千个“==="比一千个“=="=====================================================

这个建议不是因为性能问题,而是因为类型强迫意味着(‘\t\r\n' == 0)是真实的。

* 主持人 === vs == *

1 == true    =>    true
true == true    =>    true
1 === true    =>    false
true === true    =>    true