Open In App

Underscore.js _.always() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The _.always() method takes a value and returns a function that will always return that value.

Syntax:

_.always( value );

Parameters: 

  • value: This method takes a value to be returned.

Return Value: This method returns a function.

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:

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var gfgFunc = _.always('Geeks');
console.log(gfgFunc());


Output:

Geeks

Example 2: 

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var gfgFunc = _.always(1);
console.log("Value returned is",gfgFunc());


Output:

Value returned is 1

Last Updated : 19 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads