title: checking for typeof error in JS
body: <p>In JS it doesn't seem possible to check if an argument passed to a function is actually of the type 'error' or an instance of Error.</p>
  
  <p>For example, this is not valid:</p>
  
  <p><code>typeof err === 'error'</code></p>
  
  <p>since there are only 6 possible types (in the form of strings):</p>
  
  <p>The typeof operator returns type information as a string. There are six possible values that <code>typeof</code> returns:</p>
  
  <blockquote>
    <p>"number", "string", "boolean", "object", "function" and "undefined".</p>
  </blockquote>
  
  <p><a href="https://msdn.microsoft.com/library/259s7zc1%28v=vs.94%29.aspx" rel="noreferrer" title="MSDN JS typeof info">MSDN</a></p>
  
  <p>But what if I have a simple use case like this:</p>
  
  <pre><code>function errorHandler(err) {
  
      if (typeof err === 'error') {
          throw err;
      }
      else {
          console.error('Unexpectedly, no error was passed to error handler. But here is the message:',err);
      }
  }
  </code></pre>
  
  <p>so what is the best way to determine if an argument is an instance of Error?</p>
  
  <p>is the <code>instanceof</code> operator of any help?</p>