Checks if a value is an instance of Error or a specific error type.
A specific error type that extends the Error class.
Error
The value to check. It can be of any type.
Optional
(Optional) A specific error type to validate against.
Returns true if the value is an instance of Error or the specified error type, otherwise false.
true
false
const error = new Error('An error occurred');console.log(isError(error)); // trueconst typeError = new TypeError('A type error occurred');console.log(isError(typeError, TypeError)); // true Copy
const error = new Error('An error occurred');console.log(isError(error)); // trueconst typeError = new TypeError('A type error occurred');console.log(isError(typeError, TypeError)); // true
Checks if a value is an instance of Error or a specific error type.