JavaScript Number's Parity Detection with Bitwise AND


Example

Instead of this (unfortunately too often seen in the real code) "masterpiece":

function isEven(n) {
    return n % 2 == 0;
}

function isOdd(n) {
    if (isEven(n)) {
        return false;
    } else {
        return true;
    }
}

You can do the parity check much more effective and simple:

if(n & 1) {
    console.log("ODD!");
} else {
    console.log("EVEN!");
}

(this is actually valid not only for JavaScript)