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.
// Requiring the lodash library
const _ = require("lodash");
// Use of _.noop() method
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 equalExample 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.
// Requiring the lodash library
const _ = require("lodash");
// Use of _.noop() method
let obj = new Object(_.noop())
console.log(`Object is ${obj.Object}`)
// Use of _.noop() method
let arr = new Array(_.noop())
console.log(`Array is ${arr[0]}`)
Output:
Object is undefined
Array is undefined