Open In App

Underscore.js _.always() Method

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

Syntax:



_.always( value );

Parameters: 

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:




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

Output:

Geeks

Example 2: 




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

Output:

Value returned is 1
Article Tags :