Lodash _.noop() Method
Last Updated :
20 Oct, 2023
Lodash _.noop() method is used to return “undefined” irrespective of the arguments passed to it.
Syntax:
_.noop();
Parameters:
This method can take optional parameters of any type.
Return value:
This method returns undefined.
Example 1: In this example, we are storing the undefined value in a variable by the use of the _.noop() method and comparing it to another variable having an undefined value and checking whether both are equal or not.
Javascript
const _ = require( "lodash" );
let val1 = undefined;
let val2 = _.noop();
if (val1 == val2)
console.log( "val1 and val2 are equal" );
else
console.log(`val1 and val2 are not equal`);
|
Output:
val1 and val2 are equal
Example 2: In this example, we are creating an array and an object by the use of the _.noop() method and printing their values in the console.
Javascript
const _ = require( "lodash" );
let obj = new Object(_.noop())
console.log(`Object is ${obj.Object}`)
let arr = new Array(_.noop())
console.log(`Array is ${arr[0]}`)
|
Output:
Object is undefined
Array is undefined
Share your thoughts in the comments
Please Login to comment...