Is bol === !0 exactly the same as bol == true?
Example:
function myFunction(bol){
if(bol===!0){
return 1;
}else{
return -1;
}
}
alert(myFunction(true));//1
Will I ever run into problems if I decide to use it? (different than code readability)
No.
1 == trueistruebut1 === !0is false.Since
!0istrue, this is equivalent tobol === true. Note how you should still use the three equal signs to get exactly the same behavior.The
===means JavaScript will not try to coerce the values when comparing. If you actually want to coerce, you would use==. However, in this case, theifwill just coerce for you:is basically the same as