The operator ! (not) in JavaScript performs type coercion - it tries to convert the value to a Boolean value (true or false). 0 in JavaScript is false, therefore! 0 is the opposite of false, i.e. true.
So your first if remains the same:
if(counter % 4 != 0)
but the second one is actually
if(counter % 4 == true)
which definitely doesn't match.
Edit:
JavaScript also causes coercion when using non-strict operators != And == (compared to strict !== and === ), so in this case, if counter % 4 becomes 1, it will evaluate to true , since 1 is true value.
Here is a list of false values ββin JavaScript: http://www.sitepoint.com/javascript-truthy-falsy/
source share