+ 3
A Js property that allows you to check if a number is odd or even.
A Js property that is used to know if a given number is odd or even
5 ответов
+ 6
You can check the lowest bit of the number. If the bit is 1, then the number is odd. If the bit is 0, then the number is even.
+ 4
Or use simple maths
If the number is divisible by 2 (num % 2 ==0) the number is even, else it is odd
+ 2
n = 10
console.log(n%2===0?"even":"odd");
console.log((n&1)===0?"even":"odd");
n = 27
console.log(n%2===0?"even":"odd");
console.log((n&1)===0?"even":"odd");
+ 2
You can use different ways but the best way is to look for remainder after division,
i mean if the number divides 2 without give a reminder ( x%2 == 0) then the number is EVEN other wise the number is ODD.