title: Handling optional parameters in javascript
body: <p>I have a static javascript function that can take 1, 2 or 3 parameters:</p>
  
  <pre><code>function getData(id, parameters, callback) //parameters (associative array) and callback (function) are optional
  </code></pre>
  
  <p>I know I can always test if a given parameter is undefined, but how would I know if what was passed was the parameter or the callback?</p>
  
  <p>What's the best way of doing this?</p>
  
  <hr>
  
  <p>Examples of what could be passed in:</p>
  
  <p>1:</p>
  
  <pre><code>getData('offers');
  </code></pre>
  
  <p>2:</p>
  
  <pre><code>var array = new Array();
  array['type']='lalal';
  getData('offers',array);
  </code></pre>
  
  <p>3:</p>
  
  <pre><code>var foo = function (){...}
  getData('offers',foo);
  </code></pre>
  
  <p>4:</p>
  
  <pre><code>getData('offers',array,foo);
  </code></pre>