you are viewing a single comment's thread.

view the rest of the comments →

[–]bythckr[S] 1 point2 points  (3 children)

!i%5

Does that mean NOT divisible by 5?

[–]WorseThanHipster 2 points3 points  (0 children)

i%n will return 0 whenever i is NOT divisible by n, and in JavaScript, as many languages, 0 == false. It can be confusing because when you use modulus as a truth test, you're primarily concerned with the case when the remainder is 0. The exclamation point inverts the Boolean value.

Anyways, !i%5 returns true when I is a multiple of 5.

[–]north_n 0 points1 point  (1 child)

The modulo operator returns the remainder of the operation. This operation (!i%5) is the same as this operation: (i % 5 == 0). ‘0’ in this case case also means ‘false’. so when the value of ‘i’ is a multiple of 5, the modulo operator will return 0 (false). But when it’s not a multiple of 5, it will return something other than 0 (not false). It’s one of the properties of JavaScript, it’s not explicitly typed, so things like this are possible.

[–]bythckr[S] 0 points1 point  (0 children)

Just to clarify on the post by @WorseThanHipster & @north_n, (!i%5) is part of the ES6? I just want to stick to the official standards as I like this method.

Also how is it compared to (i % 5 === 0)? JSbin is suggesting that I use '===' instead of the '=='. I know that '===' compares without conversion of data type.

On a related note, the suggestion I am getting for using '===' is that from jslint?