Thursday, January 2, 2025
Google search engine
HomeLanguagesJavascriptLodash _.defer() Method

Lodash _.defer() Method

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.defer() method in lodash is used to defer the calling of func parameter until the recent call stack is cleared. Moreover, any further arguments are provided to func parameter of this method when it is called.

Syntax:

_.defer(func, [args])

Parameters: This method accepts two parameters which are described below:

  • func: It is the function which is to be deferred.
  • [args]: It is the arguments with which the func is being called.

Return Value: This method returns the timer id.

Example 1:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Calling defer() method with
// its parameter
_.defer(function(content) {
  console.log(content);
}, 'neveropen!');
  
// Prints content after this
console.log('Content:');


Output:

Content:
neveropen!

Example 2:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Defining func parameter
let func = number => {
  console.log(number);
};
  
// Defining for loop
for(let i = 1; i <= 5; i++) {
      
    // Calling defer() method
    // with its parameter
    _.defer(func, i);
}
  
// Prints integer after this
console.log('Integers are as follows:');


Output:

Integers are as follows:
1
2
3
4
5

Reference: https://lodash.com/docs/4.17.15#defer

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments