Override the Equivalence Comparison in Javascript

That is because the == operator doesn’t compare only primitives, therefore doesn’t call the valueOf() function. Other operators you used do work with primitives only. I’m afraid you cannot achieve such thing in Javascript. See http://www.2ality.com/2011/12/fake-operator-overloading.html for some more details.

Leave a Comment