Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36
Chrome 93
Mac OS X 10.15.7
Desktop
3 years ago
Test name Executions per second
if else 805670976.0 Ops/sec
ternary 818146240.0 Ops/sec
Script Preparation code:
AخA
 
let a = 3
Tests:
  • if else

    x
     
    let a = 3
    if(a % 2 == 0) {
        return 'even'}
    else {
        return 'odd'}
  • ternary

     
    let a = 3 
    a % 2 == 0 ? 'even' : 'odd'