Open In App

Underscore.js _.isPositive() Method

Last Updated : 05 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The _.isPositive() Method checks whether the given value is Positive or not, correspondingly returning a boolean value. 

Syntax:

_.isPositive(value);

Parameters: This method accepts a single parameter as mentioned above and described below:

  • value: Given value to be checked for a positive value.

Return Value: This method returns a Boolean value(Returns true if the given value is Positive, 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 –save

Example 1: In this example, we will see the use of the _.isPositive() method.

Javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
// Checking
console.log("The Value is Positive : " + _.isPositive(20));


Output:

The Value is Positive : true

Example 2: In this example, we will see the use of the _.isPositive() method.

Javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
// Checking
console.log("The Value is Positive : " + _.isPositive(-1000));


Output:

The Value is Positive : false

Example 3: For a string containing Positive values this method returns true.

Javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
// Checking
console.log("The Value is Positive : " + _.isPositive("100"));


Output:

The Value is Positive : true


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads