Donald Knuth
Donald Knuth

Reputation: 145

Which operator is the fastest in Javascript to check whether 2 values are equal to 0?

Which of the following is fastest and what is the justification for why?

(1) if (x == 0 and y == 0)

(2) if ((x | y) == 0)

(3) Other (Please mention. If any)

Upvotes: 0

Views: 68

Answers (1)

oreopot
oreopot

Reputation: 3450

I would probably use Strict Equality if you want to check they are exactly the same, ie they're the same type too, just in case.

if (x=== 0 && y === 0)

Upvotes: 2

Related Questions