title: Anonymous functions syntax in jQuery
body: <p>I have read lots of articles regarding jQuery and its syntax. However I have not fully understood its syntax and I would really like to get a better and deeper understanding of it.</p>
  
  <p>Many articles fail to point out the simple syntax rules (and what they are necessary for).</p>
  
  <p>As of right now I am experiencing a syntax-understanding-problem:</p>
  
  <p>my HTML:</p>
  
  <pre><code>&lt;body&gt;
      &lt;a href="http://www.jquery.com" title="anchor1"&gt;jQuery.com&lt;/a&gt;
      &lt;a href="http://www.jquery.com" title="anchor2"&gt;jQuery.com&lt;/a&gt;
      &lt;a href="http://www.jquery.com" title="anchor3"&gt;jQuery.com&lt;/a&gt;
  
      &lt;!-- JQUERY --&gt;
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
  
      &lt;script&gt;
          (function ($) {
              // EXAMPLE 1
              $("a").each(function () {
                  console.log(this.title);
              });
          })(jQuery);                      // ... everything works fine.
  
  
          (function ($) {
              // EXAMPLE 2
              $("a").each(function () {
                  console.log(this.title);
              });
          });           // ... missing (jQuery). Why isn't this working?
  
  
          $(function () {  // ... notice the $ at the beginning.
              // EXAMPLE 3
              $("a").each(function () {
                  console.log(this.title);
              });
          });           // ... missing (jQuery). Why IS this working?
  
  
              // EXAMPLE 4
              $("a").each(function () {
                console.log(this.title);
              });                          // ... everything works fine.
      &lt;/script&gt;
  &lt;/body&gt;  
  </code></pre>
  
  <p>I will clarify how I understand the code, and I would absolutely appreciate if you answer me in a very basic manner. Please do point out all my misunderstandings!</p>
  
  <p><strong>My Understanding and Questions so far:</strong><br>
  <strong>Example 1:</strong> I create an anonymous JavaScript-function. This function is executed right in that moment the browser reads it. I pass it the jQuery-Object (with ($) but I don't know why this is important at that point). From now on my function 'speaks' jQuery (it understands its syntax - I am assuming). At the very end of my JavaScript-function I pass it the jQuery object again (but why would that be necessary?). Please enlighten me.</p>
  
  <p><strong>Example 2:</strong> I tried the same function without the (jQuery) at the end. Now it is not working. I understand what is missing. But why is that (jQuery) at the end so important?</p>
  
  <p><strong>Example 3:</strong> Now I STARTED my Javascript-function with the $ and I assume that from now on my whole function is WRAPPED inside a jQuery object. Inside this jQuery-object my function understands jQuery syntax. At the end NO (jQuery) is needed.</p>
  
  <p><strong>Example 4:</strong> Here I did NOT build a JavaScript function. I just use jQuery to select and return the ("a"). This code gets executed right in the second the browser reads it. No waiting for the document to be ready.</p>
  
  <p><strong>My Question basically is:</strong><br>
  In Example 1, why is that ($) at the beginning AND the (jQuery) at the end necessary? What is the purpose?   </p>
  
  <p>I would really appreciate longer answers where I can get a deeper understanding of "reading jQuery syntax correctly" and speaking about jQuery syntax and what it requires. Thanks.</p>