2

WHICH IS FASTER?

I am wondering if there is any speed differnece at all between these, even if it is the smallest fraction. I'm assuming the strict equality operator is a little faster because it can check for exact type and fail right away if not, before doing any other tests. But I'm just guessing cause I don't really know exactly how the comparisons are made or what is done first.

This question doesn't say which is faster - Which equals operator (== vs ===) should be used in JavaScript comparisons?

Community
  • 1
  • 1
cmac
  • 3,123
  • 6
  • 36
  • 49
  • 1
    Logically `===` should be faster because it doesn't type cast – apokryfos Aug 05 '16 at 16:16
  • 2
    Check [this](http://stackoverflow.com/questions/12374815/javascript-vs-operators-performance) SO which explains the question in more detail – n0m4d Aug 05 '16 at 16:16
  • Honestly, performance between the two doesn't matter. What matters is whether the operators perform the operation that you need to express. Most of the time `===` is appropriate, whereas sometimes `==` is appropriate. – zzzzBov Aug 05 '16 at 16:20
  • 1
    @cmac check [this](http://www.adequatelygood.com/Performance-of-vs-.html) another link. According to the tests provided by the author, the === operator is roughly 10% more efficient. He also provides a spreadsheet with the results showing his findings. – n0m4d Aug 05 '16 at 16:21
  • @n0m4d http://mrale.ph/blog/2012/12/15/microbenchmarks-fairy-tale.html – Thomas Aug 05 '16 at 16:30
  • 1
    @cmac, there is no general answer, it depends pretty much on the actual data you feed into this specific comparison in this specific function *(instance)*, and how much the optimizer can optimize away (for this specific case and context). So this whole question is pointless, especially if you consider how tiny/irrelevant your potential gain is. – Thomas Aug 05 '16 at 16:30

0 Answers0