Two ways of immediate call to anonymous function (function(d){ }() ); and (function(x){ } )();
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5938802/are-function-and-function-functionally-equal-i">Are &ldquo;(function ( ) { } ) ( )&rdquo; and &ldquo;(function ( ) { } ( ) )&rdquo; functionally equal in JavaScript?</a>  </p>
</blockquote>



<p>My question having these special characters, I couldn't find a good answer. (Does anyone know how to search with them?)  </p>

<p>I've seen two patterns to immediately calling anonymous functions <a href="http://jsfiddle.net/ukqS8/1/" rel="nofollow">http://jsfiddle.net/ukqS8/1/</a></p>

<pre><code>(function(d) {
    document.write(d*2);
})(3);
</code></pre>

<p>and</p>

<pre><code>(function(x) {
    document.write(x*2);
}(3));
</code></pre>

<p>The difference being where (3) is placed: inside or outside the closing parenthesis.</p>

<p>I found a good explanation for the second case here:</p>

<p><a href="http://stackoverflow.com/questions/4806150/javascript-function-vs-function">javascript function vs. ( function() { ... } ());</a></p>

<p>which I understood as <code>function(x) {...}</code> creates a function object, (3) becomes its argument, and the enclosing () tells the interpreter that what's inside is a statement.</p>

<p>In the first case, it appears to make <code>(function(d) {...})</code> a statement that somehow is also a function, and then apply (3) to this statement/function.</p>

<p>So, they both appear to execute the same way. Is there really a difference here? Scope (I doubt it)? Is either option preferable?</p>
