How to use the isBoolean function from underscore

Find comprehensive JavaScript underscore.isBoolean code examples handpicked from public code repositorys.

underscore.isBoolean is a function that checks whether a value is a boolean or not, and returns a boolean value of true or false.

921
922
923
924
925
926
927
928
929
930
    }

};

function getOptional( k, optional, req ) {
    if( _.isBoolean( optional ) )
        return optional;

    if( _.has( optional, "permission" ) )
        return k.reg("admin").allowed( req, optional.permission );
fork icon3
star icon9
watch icon1

+ 5 other calls in file

266
267
268
269
270
271
272
273
274
275
 * @return {Any}
 */
// eslint-disable-next-line max-params
extractValue: function(types, name, node, message, usePayload = true, useMessage = true, useConfig = true) {
  types = _.isArray(types) ? types : [types];
  usePayload = _.isBoolean(usePayload) ? usePayload : true;
  useMessage = _.isBoolean(useMessage) ? useMessage : false;
  useConfig = _.isBoolean(useConfig) ? useConfig : true;

  // search in this order
fork icon0
star icon1
watch icon1

+ 2 other calls in file

How does underscore.isBoolean work?

underscore.isBoolean is a function that takes a value as an input and returns a boolean indicating whether the value is a boolean or not. It checks if the value is either true or false. If the value is a boolean, it returns true, otherwise it returns false.

386
387
388
389
390
391
392
393
394
395
    message = this.hashMessage(message);
}

if (args.length >= 4) {
    preFixed = args.slice(-1)[0];
    preFixed = _.isBoolean(preFixed) ? !!preFixed : false;

    return this.recover(
        message,
        Account.encodeSignature(args.slice(1, 4)),
fork icon0
star icon0
watch icon5

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
const _ = require("underscore");

console.log(_.isBoolean(true)); // true
console.log(_.isBoolean(false)); // true
console.log(_.isBoolean(0)); // false
console.log(_.isBoolean(null)); // false

In this example, we first import the underscore library and assign it to the _ variable. Then, we use the _.isBoolean function to check whether various values are booleans or not. In this case, _.isBoolean(true) and _.isBoolean(false) both return true, indicating that they are indeed booleans, while _.isBoolean(0) and _.isBoolean(null) both return false, indicating that they are not booleans.