I was just curious, looking around, it seems that Javascript does not have a equals() method like Java. Also, neither == or === can be used to check iff the two operators are the same item. So how is it that Clojurescript has a == and a identical? operator?
Also, should I expect identical? to be substantially faster than == in Clojurescript?
Here’s a quick result from the Himera ClojureScript REPL:
According to Mozilla’s JavaScript Reference on Comparison Operators the
===operator does compare to see if the two operands are the same object instance, and sinceidentical?in clojurescript maps directly onto===in JavaScript it will therefore do just that.The fact that
identical?maps directly ontoa === bwould also suggest that it’ll be significantly faster than=or==since they both translate to calls tocljs.core._equiv. However, it wouldn’t surprise me if a good JavaScript JIT engine reduced all three to very similar machine code for numbers since the-equivimplementation for numbers just maps ontoidentical?: