title: Javascript - function with optional parameters as object?
body: <p>I need a function that its parameter is an object, and if I leave it empty it will load default values.</p>
  
  <p>something like:</p>
  
  <pre><code>function loadMap(args) { //args is an object and its optional
  
     //this is what I want to do, test args and load defauts if necesary
     /*
     pseudocode:
     if args.latitude is not set then
         give it a default value
  
     if args.longitude is not set then
         give it a default value
  
      end pseudocode */
  
     alert("Latitude is "+args.latitude );
     alert("Longitude is "+args.longitude );
  }
  
  //outputs the default values
  loadMap();
  
  //outputs custom values
  loadMap({latitude: "x.xxxx", longitude: "-x.xxxx"});
  
  //and should work too and output one default and one custom value
  loadMap({latitude: "x.xxxx"});
  </code></pre>
  
  <p>I found this solution in this question (<a href="https://stackoverflow.com/questions/148901/is-there-a-better-way-to-do-optional-function-parameters-in-javascript">Is there a better way to do optional function parameters in Javascript?</a>) but it requires jQuery:
  <a href="http://jsfiddle.net/xy84kwdv/" rel="noreferrer">http://jsfiddle.net/xy84kwdv/</a></p>
  
  <p>It's ALMOST what I want but I don't want to depend on a jquery function.</p>