I have a script which contains the following piece of code:
(function ($) {
// ...
})($);
Can anyone explain how to read it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
$$is in the outer scope.If the
$in the outer scope changes (by having a new value assign to it) then the value for$in the inner scope will be protected from the change (since it is a different variable).This also provides a clean scope for all other variables declared inside the function (if they use
varas they should).