If I try to compare two objects in javascript using triple equals,
object1 === object2
It checked both, type and value.
My question is, which one is tested first? type or value?
The type is checked first:
https://www.ecma-international.org/ecma-262/6.0/#sec-strict-equality-comparison
7.2.13 Strict Equality Comparison
The comparison x === y, where x and y are values, produces true or false. Such a comparison is performed as follows:
- If Type(x) is different from Type(y), return false.
After all, if you don't know what the types of two variables are beforehand, comparing their "value" will be slightly tricky without coercion (which is foridden by ===
, of course).