Skip to content Skip to sidebar Skip to footer

What Does It Do? ;jQuery.ui || (function($) {

Possible Duplicate: What is the consequence of this bit of javascript? I was browsing the source code of JQuery UI. I saw this line at the beginning of the js file: ;jQuery.ui |

Solution 1:

Breaking it down:

// make sure that any previous statements are properly closed
// this is handy when concatenating files, for example
; 
// Call the jQuery.ui object, or, if it does not exist, create it
jQuery.ui || (function($) { 

Solution 2:

Edit: Dupe of What is the consequence of this bit of javascript?

  • The leading semicolon is to make sure any previous statements are closed when multiple source files are minified into one.

  • The jQuery.ui || bit makes sure that the following function is defined only if jQuery.ui does not already exist.


Solution 3:

The javascript || will use the first value if it evaluates as true and will use the second if the first evaluates as false.

In this case I presume it checks whether jQuery.ui exists and if it does not then it will evaluate the anonymous function. If jQuery.ui does exist then || will not evaluate the second value and so the anonymous function will not be run.


Post a Comment for "What Does It Do? ;jQuery.ui || (function($) {"