Coding⏱️ 1 min read📅 2026-05-31

How to Fix: checking for typeof error in JS

Check if an argument passed to a function is actually of the type 'error' or an instance of Error.

Quick Answer: Use instanceof operator instead of typeof.

To check if an argument passed to a function is actually of the type 'error' or an instance of Error in JavaScript, you can use the instanceof operator.

🔧 Proven Troubleshooting Steps

Method 1: Using instanceof Operator

  1. Step 1: Create an error object using the Error constructor.
  2. Step 2: Check if the argument passed to the function is an instance of Error using the instanceof operator.

Example Code:

const error = new Error('Test Error');

If you want to check if an argument passed to a function is of the type 'error', use the instanceof operator like this: if (err instanceof Error) { console.log(err); }

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions