Why write code Jquery like this
jquery
Solution
This is called a closure to avoid conflicts with other libraries which are using `$`. This way you can ensure to use `$` in that function with passing `jQuery` as a param.
(function ($) {
$(function () {
.......
});
})(jQuery); //<----passing jquery to avoid any conflict with other libraries.
from the docs:
it's a best practice to pass jQuery to an IIFE (Immediately Invoked Function Expression) that maps it to the dollar sign so it can't be overwritten by another library in the scope of its execution.
This is generally used to author plugins. Read out more here
Problem
Why write code Jquery like this? ``` (function ($) { $(function () { ....... }); })(jQuery); ```