In JavaScript how do I check to see if an int is divisible by 2?
Jason
In JavaScript how do I check to see if an int is divisible by 2?
Jason
if( someNumber % 2 == 0){
}
A little faster than using modulus:
if (foo & 1) {
// odd
}
else {
// even
}
It will also always result in 1 for odd numbers regardless if the input is positive or negative, whereas modulus will return -1 for negative odd numbers. It only works for integers though, not floats.