Hacker News new | past | comments | ask | show | jobs | submit login
'===' faster than '=='? (jsperf.com)
9 points by 1p1e1 on Dec 17, 2011 | hide | past | favorite | 7 comments



'===' performs better than '==' because no type conversion is need. Are there any reasons you would use '==' instead of '==='?


When you know ahead of time that the types don't need to be coerced:

http://jsperf.com/triple-equals-vs-twice-equals/4

There's even a negligible performance improvement, at least for me (iPad WebKit Safari).


For me the "3-equals-true-non-coerced" is the fastest in Chrome 16.


I can think of two.

  * (programmer) laziness

  * if you know you want type coercion


And I just love me some good old fashioned laziness. I mean seriously THREE equals!?


Shouldn't this be obvious?


I don't get it, both on my iPad 2 (iOS 5.0.1) and my MacBook (Firefox 8.0.1) == is several times faster than === which is completely the opposite of what I would be expecting. Perhaps someone who's familiar with the internals of JavaScript JIT compilers could shed some light on it?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: