title: Check if a function is using a callback or returning a value
body: <p>In some libraries/frameworks documentations, it tells you that you can use synchronous or asynchronous function.</p>
  
  <p>For example, in <a href="http://mongoosejs.com/docs/validation.html#async-custom-validators" rel="nofollow noreferrer">Mongoose documentation</a> it says:</p>
  
  <blockquote>
    <p>Custom validators can also be asynchronous. If your validator function takes 2 arguments, mongoose will assume the 2nd argument is a callback.</p>
  </blockquote>
  
  <p>So basically when you define a function like this:</p>
  
  <pre><code>function(a){
      return false;
  }
  </code></pre>
  
  <p>Mongoose will consider it as synchronous, but we define it like this:</p>
  
  <pre><code>function(a,callback){
      setTimeout(function(){
          callback(false);
      },5000)
  }
  </code></pre>
  
  <p>It will be taken as asynchronous code.</p>
  
  <p>I've noticed the same thing with <a href="https://mochajs.org/#asynchronous-code" rel="nofollow noreferrer">Mocha testing framework</a>, in the documentation is says:</p>
  
  <blockquote>
    <p>Testing asynchronous code with Mocha could not be simpler! Simply invoke the callback when your test is complete. By adding a callback (usually named done) to it(), Mocha will know that it should wait for this function to be called to complete the test.</p>
  </blockquote>
  
  <hr>
  
  <p>My question is: <strong>How do they do this? How would you know when calling a function whether it takes 1 or 2 arguments?</strong></p>