The difference between "==" and "===" in js: 1. "==" only judges the value but not the data type, while "===" judges the value and also the data type; 2. When using "==" for comparison, the data type can be automatically converted, but "===" cannot automatically convert the data type; 3. "===" is more rigorous, and it is recommended to use "===";
The operating system of this tutorial: windows10 system, JavaScript ECMAScript 2021 version, DELL G3 computer.
The difference between = = and === in js
= = and === are both used to determine equality , the difference is: equal degree of depth.
1.= = only judges the numerical value but not the data type. In other words, when using = = for comparison, it can automatically convert the data type for us;
2.=== determines the degree of equality deeper than ==, that is, it determines both the numerical value and the data type, and the data type cannot be automatically converted.
1, = = (the judgment values are equal)
let a = 1; //数字类型 let b = ‘1’; //字符类型console.log(a==b);123
Result: true
2, === (congruent, judgment values and types All equal)
let a = 1; //数字类型 let b = ‘1’;//字符类型 console.log(a===b);123
Result: false
Note: = = will automatically convert the data type, so sometimes some problems will occur, for example:
let a = 1;let b = true;console.log(a==b);//结果是true123 let a = 0;let b = false;console.log(a==b);//结果是true123 let a = null;let b = undefined;console.log(a==b);//结果是true123
Summary: === is more rigorous, it is recommended to use ===
The above is the detailed content of The difference between == and === in js. For more information, please follow other related articles on the PHP Chinese website!