Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Javascript Check if number is even or odd

function solution(num) {
    return num % 2 === 0 ? 'Even' : 'Odd'
}

Comment

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 ); };
Comment

javascript check if a number is even or odd

const isEven = num => num % 2 === 0;

console.log(isEven(2)); 
// Result: True
Comment

odd number is javascript

let arr = [1,2,3,4,5,6,7,8,9,10,11,12]

let odds = arr.filter(n => n%2)

console.log(odds)
 Run code snippetHide results
Comment

PREVIOUS NEXT
Code Example
Javascript :: angular add a new line from component 
Javascript :: add property to object conditionally 
Javascript :: javascript xor 
Javascript :: jquery $(document.on click 
Javascript :: [Error - 10:52:45 PM] Failed to load jshint library 
Javascript :: jquery today date 
Javascript :: javascript string contains 
Javascript :: typeorm get data from a table by array of id 
Javascript :: how to hide button in react 
Javascript :: moment time ago format reactjs 
Javascript :: method to look for objects in arrays by id 
Javascript :: momentjs range 
Javascript :: mongoose delete request 
Javascript :: react-native run-ios command 
Javascript :: react check if mounted 
Javascript :: heroku scripts 
Javascript :: javascript string starts with 
Javascript :: get closest element id jquery 
Javascript :: tsconfig.json not generated 
Javascript :: three js render 
Javascript :: object to array javascript 
Javascript :: javascript class inheritance 
Javascript :: js draw circle 
Javascript :: react font awesome 
Javascript :: how to declare a variable inside a class in javascript 
Javascript :: foreach loop in react 
Javascript :: javascript force precision to 2 decimal numbers 
Javascript :: change href without reloading page js 
Javascript :: saveas angular 6 
Javascript :: trim string after - in jquery 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =