Find if variable is divisible by 2

sadmicrowave picture sadmicrowave · May 12, 2010 · Viewed 237.5k times · Source

How do I figure out if a variable is divisible by 2? Furthermore I need do a function if it is and do a different function if it is not.

Answer

Andy E picture Andy E · May 12, 2010

Use modulus:

// Will evaluate to true if the variable is divisible by 2
variable % 2 === 0