Here’s a one-liner in JavaScript to check if a number is even or odd:
num % 2 === 0 ? "even" : "odd";
Replace num
with the actual number you want to check. This expression uses the ternary operator (?
) to check if the remainder of num
divided by 2 is equal to 0. If it is, the expression returns "even"
, otherwise it returns "odd"
.
Thank you for reading, and let’s have conversation with each other
Thank you for reading my article. Let’s have conversation on Twitter and LinkedIn by connecting.