Skip to content
Related Articles

Related Articles

Underscore.js _.isEven() Method
  • Last Updated : 30 Jul, 2020

The _.isEven() method checks whether the given value is Even or not, and returns the corresponding boolean value. 

Syntax:

_.isEven( value );

Parameters: 

  • value: Given value to be checked for even value.

Return Value: This method returns a Boolean value(Returns true if the given value is even, else false).

Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed. Underscore.js contrib library can be installed using npm install underscore-contrib .



Example 1:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable
var _ = require('underscore-contrib');
   
// Checking
console.log("The Value is Even : " + _.isEven(44));

chevron_right


Output:

The Value is Even : true

Example 2:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
// Checking
console.log("The Value is Even : " + _.isEven(21));

chevron_right


Output:

The Value is Even : false

Example 3: For value: 0, this method returns true.

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
// Checking
console.log("The Value is Even : " + _.isEven(0));

chevron_right


Output:

The Value is Even : true

Example 4: For non-integer values, this method returns false.

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
// Checking
console.log("The Value is Even : " 
    + _.isEven("GeeksforGeeks"));

chevron_right


Output:

The Value is Even : false

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :