In hacking on the gRaphaĆ«l code base, I came across a recurring pattern syntax pattern I hadn’t encountered in JavaScript before.
Essentially, instead of using this very common conditional construct:
if (a) b;
The author uses:
!a && b;
Similarly,
if (a) b; else c;
Is written:
!a && b; a && c;
I was curious about the performance difference between the styles, and wrote a benchmark to compare them.
I only tested in WebKit nightly 53415, but I found that in every case, the if / if-else construct outperformed the pure-logic construct. The differences in performance are admittedly negligible, so I’ll be sticking to if-else for readability, and I’ll accept the performance benefit as a happy side-effect.
Leave a Comment