Open In App

Lodash _.isError() Method

Lodash _.isError() Method checks whether the given value is a type of error or not and returns the corresponding boolean value.

Syntax:

_.isError(value);

Parameters:

Return Value:

This method returns a Boolean value(Returns true if the given value is an error, else false).



Example 1: In this example, we are getting a ‘true’ value as a new Error is an object.




// Defining Lodash variable
const _ = require('lodash');
 
// Checking for Error Value
console.log("The Value is Error : "
    + _.isError(new Error));

Output:



The Value is Error : true

Example 2: In this example, we are getting a ‘false’ value as Err is not an object.




// Defining Lodash variable
const _ = require('lodash');
 
// Checking for Error Value
console.log("The Value is Error : "
    + _.isError("Err"));

Output:

The Value is Error : false 
Article Tags :