Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Chrome 123
Mac OS X 10.15.7
Desktop
11 months ago
Test name Executions per second
Number + isNaN 3861.5 Ops/sec
Number.parseInt + Number.isInteger 41600.2 Ops/sec
Number.parseInt + simple condition 46032.6 Ops/sec
HTML Preparation code:
AخA
 
1
<div class="container"></div>
Script Preparation code:
x
 
const container = document.querySelector('.container');
const cloneTarget = document.createElement('div');
const listToInsert = document.createElement('div');
listToInsert.id = 'clone-list';
for (let i = 0; i < 100; i++) {
    const clone = cloneTarget.cloneNode(true);
    clone.id = "clone_" + i;
    clone.textContent = 'I am clone ' + i;
    listToInsert.append(clone);
}
container.append(listToInsert);
var elements = document.querySelectorAll('#clone-list *');
Tests:
  • Number + isNaN

     
    for (let el of elements) {
        const zIndex = Number(el.style.zIndex);
        if (!isNaN(zIndex)) {
            console.log(true);
        }
    }
  • Number.parseInt + Number.isInteger

     
    for (let el of elements) {
        const zIndex = Number.parseInt(el.style.zIndex, 10);
        if (Number.isInteger(zIndex)) {
            console.log(true);
        }
    }
  • Number.parseInt + simple condition

     
    for (let el of elements) {
        const zIndex = Number.parseInt(el.style.zIndex, 10);
        if (zIndex || zIndex === 0) {
            console.log(true);
        }
    }