Lodash _.noop() 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 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.
Returns: This method returns undefined.
Example 1:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.noop() method let val = undefined; let val2 = _.noop(); if (val == val2) console.log( "val and val2 are equal" ); else console.log(`val and val2 are not equal`); |
Output:
val and val2 are equal
Example 2:
Javascript
// 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