Is zero even or odd

Is 0 even or is zero odd?
Zero is an even number. It is true that when it comes to classifying zero as a positive or negative number, one would explain how zero is not positive nor negative. However, when it come to being an odd or even integer is another matter.

The easy way to remember why zero is an even number is to think this way:

  1. Is the number that comes after zero an even number, or an odd number?
    Answer: after zero comes an odd number, which is 1.
  2. What about before zero, is the number odd or even?
    Answer: before zero the number is odd because it is -1.

Let’s prove this is so.
Fire up your Chrome or Opera console by pressing CTRL SHIFT j
Try the following code and observe the results:

-1 % 2 === 0;
// returns false
1 % 2 === 0;
// returns false
0 % 2 === 0;
// returns true

Note: % represents the modulus or the remainder of the division between the left and right values. When the remainder is zero in a division by 2, the number being divided is an even number. Else, the number is odd.

Advertisements

Author: tarau

technical writer, web technologies

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s