Underscore.js _.not() 方法
这 _。 not () 方法返回一个布尔值,它与给定值的真实性布尔值相反。
句法:
_.not( value );
参数:
- value:返回相反布尔值的给定值。
返回值:此方法返回一个布尔值。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 underscore.js contrib 库。 Underscore.js contrib 库可以使用npm install underscore-contrib –save 安装。
示例 1:它为此方法返回 false。
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bool = _.not( true );
console.log("Opposite boolean value if"
+ " value's truthiness is : ", bool);
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bool = _.not( false );
console.log("Opposite boolean value if"
+ " value's truthiness is : ", bool);
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bool = _.not( "Geeks" );
console.log("Opposite boolean value if"
+ " value's truthiness is : ",bool);
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bool = _.not( null );
console.log("Opposite boolean value if"
+ " value's truthiness is : ", bool);
输出:
Opposite boolean value if value's truthiness is : false
示例 2:对于 false,此方法返回相反的值,即 true。
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bool = _.not( false );
console.log("Opposite boolean value if"
+ " value's truthiness is : ", bool);
输出:
Opposite boolean value if value's truthiness is : true
示例 3:对于现有值,此方法返回 false。
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bool = _.not( "Geeks" );
console.log("Opposite boolean value if"
+ " value's truthiness is : ",bool);
输出:
Opposite boolean value if value's truthiness is : false
示例 4:对于不存在的值,此方法返回 true。
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bool = _.not( null );
console.log("Opposite boolean value if"
+ " value's truthiness is : ", bool);
输出:
Opposite boolean value if value's truthiness is : true