Numbers Parity Detection with Bitwise AND

suggest change

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)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents