Q: Efficient way to compare to zero Condition: having a cycle where I do something if some numeric variable(i.e. moreThanZero ) is not a zero(usually more than...). Many-many cycles, say more than a million, what is the most efficient/fast way to compare:
if ( !moreThanZero ) { ... }
if ( moreThanZero > 0 ) { ... }
if ( moreThanZero != 0 ) { ... }
if ( moreThanZero !== 0 ) { ... }

thanks to @torazaburo
if ( 0 !== moreThanZero ) { ... }

or other options?

A: http://jsperf.com/comparetozero1
the difference seems to tiny to make a difference , I would go for comparing the type too with === , because 0 == '' is true

A: I am assuming that you are talking about loops, and a comparing variable in it.
If so,
If you want to compare a variable in a loop of millions of iteration, I would like you to prefer this.
 if ( moreThanZero > 0 ) 
 {
 // Your code goes here.......
 }  

Because,
if ( !moreThanZero ) { //Do something } says Do  something if moreThanZero is not zero. It doesn't mean that moreThanZero is Greater than zero, it might be Less than zero too..
if ( moreThanZero != 0 ) { ... } will also be discarded for the same reason.
So,  if ( moreThanZero > 0 ){.....} might be the answer you were expecting.  

A: You're probably micro-optimizing and unlikely to see any major difference in a large program from the cost of one comparison against zero. However, for the sake of science...
Tweaking the benchmark written by @AbrahamAdam to prevent most common optimizations (optimizing the loop out, removing variable writes, etc) and just calling a blackhole(ish) function instead, I see a probably significant difference: http://jsperf.com/comparetozero1/3
Speculating as to why the results pan out they way they do:
!n is the least-specific operation tested. At the very least, it has to (in some fashion) treat the variable as a boolean. While some optimization can be done and some compilers may be smart enough to use a bitwise not or numeric comparison, the language allows much more work to be done.
=== and !== explicitly don't do type coercion, so they are likely to be reliably fast, with the caveat that both operands must be the same type or they aren't equal. For numbers, this likely becomes an integer comparison, which should map down to the cmp instruction.
> may, and in modern browsers likely does, take advantage of optimizations when both operands are known to be numeric and especially integral. Comparing against a constant, especially 0, is an ideal case: there's an assembly instruction that compares to 0.
