I was looking at the jQuery UI code, and I found that every file starts with a construct like this:
jQuery.ui || (function($) {
My question is: why is there a semicolon before jQuery, and why is the logical OR being done?
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.
The semi-colon is there to ensure safe file concatenation. (libraries and library components are frequently packed into a single file)
The self-invoking anonymous function on the right hand-side will only run if the left-hand-side of the statement evaluates to a falsey value. So if
jQuery.uialready exists on the page then the function will not run. It only runs whenjQuery.uidoes not yet exist.