I see in some javascript codes that people write something like this:
var myVar = "true";
//...
if(myVar == "true") {
//...
}else{
//...
}
Why people don’t use TRUE or FALSE? As far as I know boolean type is obvious for browsers.
Or is just a poor code … and try to never write in this way.
It’s just poor code. Try to never write in this way.
This kind of code is just horrible for maintainability. Both the
==(instead of===) and thetrueas string.PS: besides,
"true" == true // false. For the===argument, it’s simply becausetrue == 1 // true, and a lot of others look alike stuff like this.