DEV Community

Discussion on: 7 Killer JavaScript One-Liners that you must know

Collapse
 
jchlu profile image
Johnny C-L

This is what the modulus operator % is for. By negating the check, you return 1 (true) or 0 (false) with:
console.log(!num % 2)

Collapse
 
prakhart111 profile image
Prakhar Tandon

Modulus checks if the number is divisible by a number or not, It doesn't checks for exponent.