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); }, 'zambiatek!');  Â// Prints content after this console.log('Content:'); | 
Output:
Content: zambiatek!
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, zambiatek 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!
 
				 
					


