Double or Triple?
I would like to go back to the old school days when scoring the brownie points in essay-writing tests would be guaranteed if you begin it with a quote -
The worst form of inequality is to try to make unequal things equal.
-Aristotle
Having quoted that, I would like to safely say that’s exactly what the double equal to (==) operator sometimes end up doing (using coercion — discussed below) in the world of JavaScript.
It follows the Abstract Equality Comparison algorithm and provides loose equality value-comparisons. On the other hand, triple equals (===) is based on the Strict Equality Comparison algorithm.
For stacking in my internal memory, I have had them saved as === checks for type equality along with the value whereas, == eliminates the type check and dives straight into checking the values of the two variables involved. And thereby I assumed that performance wise == would give faster results. I was wrong. It was a very naive approach.
Double Equals also checks the type. It performs a type conversion when comparing two things. Converting a value from one type to another is often called “type casting,” when done explicitly, and “coercion” when done implicitly (forced by the rules of how a value is to be used). Therefore, Double Equals evaluates using Type Coercion. There are six primitive data types in JavaScript, namely — Null, Boolean, String, Number, Undefined and Symbol (new in ES6). Before initiating the comparison, the compiler checks if any of the operands are coercible and converts it to be of an equivalent type matching to that of the other operand. This increases the time and thus, reduces the performance.
Eg.,
console.log(num == obj); // true
console.log(num == str); // true
console.log(obj == str); // true
console.log(null == undefined); // trueTriple Equals operand does not convert any of the types implicitly. If the operands are of different types, they are deemed unequal. The output is easy to predict and is reliable.
// both false, except in rare cases
console.log(obj == null);
console.log(obj == undefined);I executed a simple test on https://jsperf.com to check the performance of double v/s triple equals operator. The result showed that Double Equal was 87% slower. Refer the screenshot below.

Therefore, for faster evaluation and to avoid ambiguity and uncertainties in the output, we should prefer using Triple over Double.