Removing a single character is hardly worth the issues that may arise from not using it. The only quasi-acceptable use of '==' IMHO is:
myVar == null
as it is a little easier than: myVar === undefined || myVar === null
That said, I use only '===' as I don't want to ever worry about my code (plus, the use of a maybe monad makes this and other problems go away).
Re:JavaScript Equality Table
by paracaidista on Saturday December 27, 2014 @05:26AM
(#8802241)
== vs. === aside, it's a bit hypocritical to use === because it's safer when you're using undefined as a keyword. You can't tell just from looking at that line whether the variable undefined is actually undefined or not; it could, in fact, be defined (below the global scope, that is -- unless you're in an older browser, I suppose).
Granted, defining a variable called undefined would be absurd, and I realize I'm nitpicking here, but if we're trying to make a point about good practice, typeof would be the way to go. (Of course, more often you only really care if something == null or not, so you'd just do a simple == null check, like you said.)
Well, there is a reason: consistency. ;)
I hate seeing "==" in code because it's rarely clear whether the programmer intends it to coerce or just didn't bother with the third keystroke. So "===" is just enforced everywhere through jshint.
Might the === comparison be faster, since the underlying JavaScript engine doesn't need to determine how the two types should be cast back and forward to be compared?
Re:JavaScript Equality Table
by Xophmeister on Friday December 26, 2014 @04:59PM
(#8800586)
Yep, === will be quicker if the types are the same.
Re:JavaScript Equality Table
by SamReidHughes on Friday December 26, 2014 @05:25PM
(#8800696)
Yes there is a reason, because somebody reading the code is going to have to wonder why the heck you used a double-equals, and the code could be edited later in such a way that the triple-equals becomes relevant again.
1. http://www.ecma-international.org/ecma-262/5.1/#sec-11.4.3