Skip to content
Related Articles

Related Articles

Improve Article

Underscore.js _.always() Method

  • Last Updated : 19 Aug, 2020

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
My Personal Notes arrow_drop_up
Recommended Articles
Page :