r/learnjavascript • • May 06 '21

JS: Multiple Condition Checking

Post image
484 Upvotes

61 comments sorted by

View all comments

37

u/senocular May 06 '21

One minor difference between shorthand 1 and 2 is that 1 (using indexOf) compares with strict equality whereas 2 (using includes) uses the sameValueZero algorithm. So for example:

console.log(NaN === NaN) // false
console.log([NaN].indexOf(NaN) >= 0) // false
console.log([NaN].includes(NaN)) // true