chain of or equals vs Array.includes
What works best when value misses all the conditions.
Date tested:
one year ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Test name
Executions per second
wUmrLVWz
1.0 Ops/sec
wUmrLVWz
1.0 Ops/sec
wUmrLVWz
1.0 Ops/sec
wUmrLVWz
1.0 Ops/sec
wUmrLVWz
1.0 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var x = 3; var list = [undefined, NaN, null, ''];
Tests:
Array.includes
[undefined, NaN, null, ''].includes(x)
Or chain
x === undefined || Number.isNaN(x) || x === null || x === ''
Or chain (witch cheap 'undefined' check)
typeof x === 'undefined' || Number.isNaN(x) || x === null || x === ''
Array.includes with predefined list
list.includes(x)
Array.includes with predefined list (witch cheap 'undefined' check)
typeof x === 'undefined' || list.includes(x)
Open this result on MeasureThat.net