title: What is 'typeof define === 'function' && define['amd']' used for?
body: <p>What purpose does the following code serve? What does factory function do here? Here root is window object. Is factory a default java script function? In what kind of scenarios this type of code can be used. This code is from <a href="http://simontabor.com/labs/toggles/" rel="noreferrer">toggle.js from Simon Tabor</a>. Zepto and ender are libraries. Is this mostly used in libraries.</p>
  
  <pre><code>   if (typeof define === 'function' &amp;&amp; define['amd']) {
          define(['jquery'], factory);
       } else {
        factory(root['jQuery'] || root['Zepto'] || root['ender'] || root['$']|| $);
      }
  </code></pre>