Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript is number even or odd

// vanilla
function isEven(num) {
   return num % 2 == 0;
}

function isOdd(num) {
   return Math.abs(num % 2) == 1;
}

// ES6
const isEven = num => ((num % 2) == 0);

//bitwise AND operator
const isOdd = function(num) { return num & 1; };
const isEven  = function(num) { return !( num & 1 ); };
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #number #odd
ADD COMMENT
Topic
Name
4+1 =