Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok I figured it out after doing some research but I will leave the answer in for others.</p> <p>Basically it's to <strong>avoid conflicts with other javascript libraries</strong> which also use the dollarsign. </p> <p>So Jquery advices to use <strong>jQuery or window.jQuery instead of the dollar sign</strong>. It's usually used in combination with <strong>jQuery.noConflict()</strong> to make jQuery give up on the $ sign used in other javascript libraries when you <strong>mix libraries</strong>.</p> <p>This is actually a way of running a <strong>self-executing function</strong> that <strong>passes in</strong> the <strong>window.jQuery object</strong> and passes it <strong>on to the $</strong> sign. This way you can keep using the dollar sign in your code without having to worry about other javascript libraries that could cause a conflict with your code.</p> <p><strong>Wrapping it up in this function saves yourself from using window.jQuery everywhere</strong> to replace the $ sign.</p> <p>If you <strong><code>execute function () {}()</code></strong> like this it results in a <strong>syntax error</strong> as it's just a function declaration. The <strong>! turns it into an expression</strong> which can be executed.</p> <p>So basically you can use both for the same purpose.</p> <pre><code>!function($){}() (function($){})() </code></pre> <p>Feel free to modify or complement.</p> <p>references: </p> <ul> <li><a href="https://stackoverflow.com/questions/8305288/what-is-the-purpose-of-this-function-function-code-here-jquery">What is the purpose of this? (function ($) { //function code here })(jQuery);</a></li> <li><a href="https://stackoverflow.com/questions/3755606/what-does-the-exclamation-mark-do-before-the-function">What does the exclamation mark do before the function?</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload