title: Using Facebook's invariant vs if throw
body: <p>I've been looking at various Node.js projects' source, and I've noticed that some people use <a href="https://github.com/zertosh/invariant" rel="noreferrer">invariant</a>. From what I understood, <code>invariant</code> is a tool that lets you put assertions in your code, and raise errors as needed.</p>
  
  <h1>Question:</h1>
  
  <p>When would you favor using <code>invariant</code> vs throwing errors the traditional way?</p>
  
  <pre><code>// Using invariant
  function doSomething(a, b) {
     invariant(a &gt; b, 'A should be greater than B');
  }
  
  // If throw
  function doSomething(a, b) {
     if(a &lt;= b) {
        throw new Error('A should be greater than B');
     }
  }
  </code></pre>