Related Articles

Related Articles

Lodash _.always() Method
  • Last Updated : 18 Sep, 2020

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

Syntax:

_.always( value );

Parameters: This method takes a single parameter as listed above and discussed below.

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

Return Value: This method returns a function.

Note: To execute the below examples, you have to install the lodash-contrib library by using this command prompt and execute the following command.



npm install lodash-contrib

Below examples illustrate the Lodash _.always() method in JavaScript:

Example 1:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Use of _.always() function
var gfgFunc = _.always('GeeksforGeeks : Computer Science Portal');
  
console.log(gfgFunc());

chevron_right


Output:

GeeksforGeeks : Computer Science Portal

Example 2: 

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Value returned is : 10000

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :