JavaScript performance difference between double equals (==) and triple equals (===)

前端 未结 6 397
刺人心
刺人心 2020-11-29 06:06

In JavaScript, is there a performance difference between using a double equals (==) vs using a triple equals (===)?

Example: if (foo

6条回答
  •  旧巷少年郎
    2020-11-29 06:56

    From some flimsy tests, == appears to be marginally quicker than ===.

    By marginally, I mean that I can see a few milliseconds difference on interations of many millions of tests. You can't possibly need the performance gain, rather than using whatever is most correct for the task at hand.

    EDIT: actually, seems to depend on /what/ you're comparing and the browser implementation. In other words, don't worry about it.

提交回复
热议问题