Home  >  Article  >  Web Front-end  >  Instructions for using the javascript equal sign operator_Basic knowledge

Instructions for using the javascript equal sign operator_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 18:25:591381browse

In the past, the equal sign "==" was always used, and the equal sign "===" was never used in JS. When these two operators only detect the equality of two objects, one performs type conversion and the other does not. The equals symbol will only return true before type conversion is not performed

Copy code The code is as follows:

var sNum="66";
var iNum=66;
alert(sNum ==iNum);//The output is true
alert(sNum===iNum);//The output is false

The first equal operator replaces sNum during comparison The value "66" is converted into a numeric type, and then compared with iNum, so it will return true
. However, the second comparison of congruent signs does not perform type conversion, so the comparison between string and numeric types cannot be true, so all Return false
There is also a non-congruent sign and non-equal sign

Copy code The code is as follows:

var sNum="66";
var iNum=66;
alert(sNum!=iNum); //Returns to false
alert(sNum!===iNum); //Returns to true

The first operator is easy for everyone to understand. The operator converts sNum into a numeric type. After converting to a numeric type, the two values ​​​​are equal and return false
The second operator non-equal sign does not convert the sNum type, so sNum is not equal to iNum, so the return value is true
This is just one of my study notes haha.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn