Is Number Even - Javascript Number Operation

Javascript examples for Number Operation:Number Algorithm

Description

Is Number Even

Demo Code



function isEven(num) {
  if (num == 0) {
    return true;/*from w w w .jav  a  2s.  co  m*/
  } else if (num == 1) {
    return false;
  } else if (num < 0) {
    return isEven(Math.abs(num));
  } else {
    return isEven(num - 2);
  }
}

console.log(isEven(50));
console.log(isEven(75));
console.log(isEven(-1));

Related Tutorials