How to determine if a number is odd in JavaScript

Use the below code:

function isOdd(num) { return num % 2;}
console.log("1 is " + isOdd(1));
console.log("2 is " + isOdd(2));
console.log("3 is " + isOdd(3));
console.log("4 is " + isOdd(4));

1 represents an odd number, while 0 represents an even number.

Leave a Comment