The difference between == and === is that == performs conversions. So, for example, 1 will be == to '1' , but not === to '1' . The reason this approach is preferable when you check for undefined is because JavaScript has known barriers to comparison.
The most common:
'' == '0' //false 0 == '' //true 0 == '0' //true false == 'false' //false false == '0' //true false == undefined //false false == null //false null == undefined //true " \t\r\n" == 0 //true
So, with === you avoid the null == undefined problem, which can lead to hard-to-reach errors. This is why you should use == instead of === . Since === does not perform any conversions behind the scenes, this is also a faster operation.
In this particular case, this will not affect the result. Whether you use typeof a == 'undefined' or typeof a === 'undefined' , the output will be the same without error. This is because typeof returns a string. However, the operation will be faster, so you will have a slight increase in productivity.
source share