title: JavaScript anonymous function expression vs IIFE
body: <p>Encountered some code that's using IIFEs in an expression rather than just a normal function.</p>
  
  <pre><code>var custom_type = (function() {
      return $('#myDiv').attr('custom_type');
  })();
  </code></pre>
  
  <p>Normally I would write this as something like:</p>
  
  <pre><code>var custom_type = function() {
      return $('#myDiv').attr('custom_type');
  };
  </code></pre>
  
  <p>What's the reason for the IIFE?  The only thing I can think of is that the IIFE might assign the <code>custom_type</code> variable only once at the beginning whereas the second might continue to check for the updated type every time the variable is referenced.</p>