Underscore.js _.isEven() 方法
这 _。 isEven () 方法检查给定值是否为偶数,并返回相应的布尔值。
句法:
_.isEven( value );
参数:
- value:要检查偶数的给定值。
返回值:此方法返回一个布尔值(如果给定值是偶数则返回真,否则返回假)。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 underscore.js contrib 库。 Underscore.js contrib 库可以使用npm install underscore-contrib 安装。
示例 1:
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Even : " + _.isEven(44));
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Even : " + _.isEven(21));
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Even : " + _.isEven(0));
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Even : "
+ _.isEven("GeeksforGeeks"));
输出:
The Value is Even : true
示例 2:
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Even : " + _.isEven(21));
输出:
The Value is Even : false
示例 3:对于值:0,此方法返回 true。
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Even : " + _.isEven(0));
输出:
The Value is Even : true
示例 4:对于非整数值,此方法返回 false。
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
// Checking
console.log("The Value is Even : "
+ _.isEven("GeeksforGeeks"));
输出:
The Value is Even : false