How to determine if a number is odd in JavaScript

后端 未结 27 1794
一向
一向 2020-11-27 10:05

Can anyone point me to some code to determine if a number in JavaScript is even or odd?

27条回答
  •  眼角桃花
    2020-11-27 10:45

    By using ternary operator, you we can find the odd even numbers:

    var num = 2;
    result = (num % 2 == 0) ? 'even' : 'odd'
    console.log(result);

提交回复
热议问题