Explain to me like I am five

Could you explain to me like I am five years old following statement? i % 2 !== 0

The first part is the modulo or remainder operator. It means “what is the integer part leftover after doing integer division” so i % 2 means the remainder after dividing by 2. For even numbers the remainder after dividing my two is 0. For odd numbers, the remainder after dividing by 2 is 1.

The !== is the “not equal to” operator. It returns true if the arguments are not equal.

So, putting that together this statement says “return true if the remainder after dividing i by 2 is not equal to 0” which in other words means “return true if i is not even” (since even numbers would have a remainder of 0) which could be stated even more simply as “is i odd?”

Hope that helps. Ask away it you need more clarification.

1 Like