Files
30-seconds-of-code/snippets/even-or-odd-number.md
2017-12-12 07:11:37 -05:00

9 lines
242 B
Markdown

### Even or odd number
Use `Math.abs()` to extend logic to negative numbers, check using the modulo (`%`) operator.
Return `true` if the number is even, `false` if the number is odd.
```js
const isEven = num => Math.abs(num) % 2 === 0;
```