+ 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

11th Jun 2023, 10:13 PM
Cyril 4L👨‍💻🔥
Cyril 4L👨‍💻🔥 - avatar
5 Respuestas
+ 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.
11th Jun 2023, 11:12 PM
Brian
Brian - avatar
+ 4
Or use simple maths If the number is divisible by 2 (num % 2 ==0) the number is even, else it is odd
12th Jun 2023, 7:22 AM
Ugulberto Sánchez
Ugulberto Sánchez - avatar
12th Jun 2023, 5:24 PM
Cyril 4L👨‍💻🔥
Cyril 4L👨‍💻🔥 - avatar
+ 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");
12th Jun 2023, 10:10 AM
Bob_Li
Bob_Li - avatar
+ 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.
13th Jun 2023, 7:42 PM
ERICK ERNEST
ERICK ERNEST - avatar