Run details:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0
Firefox 83
Ubuntu
Desktop
4 years ago
Test name Executions per second
typeof value === "boolean" 23981.9 Ops/sec
value === true || value === false 9623.1 Ops/sec
Script Preparation code:
AخA
 
var values = Array.from({length: 10000}, (_, i) => i % 5 === 0 ? i % 3 === 0 : i % 2 ? i.toString() : i);
Tests:
  • typeof value === "boolean"

     
    let bools = 0;
    for (let i = 0; i < values.length; i++) {
      const value = values[i];
      if (typeof value === "boolean") {
        bools++;
      }
    }
  • value === true || value === false

     
    let bools = 0;
    for (let i = 0; i < values.length; i++) {
      const value = values[i];
      if (value === true || value === false) {
        bools++;
      }
    }