tags:

views:

522

answers:

1
+3  Q: 

JQuery ui.core.js

I found the beginning of the code of ui.core.js of JQuery UI quite interesting,

;jQuery.ui || (function($) {
// code...
})(jQuery);

What is the reason to have ';' in the front?

+7  A: 

It is there for concatenation purposes in case one would want to concatenate this file at the end of another script. It effectively fool-proofs concatenation to scripts that have not been terminated properly by a semi-colon.

So, given the following script:

alotOfJsCode(argument);
var fileEnd = noSemiColon

The semi-colon at the beginning allows to prevent this:

alotOfJsCode(argument);
var fileEnd = noSemiColonjQuery.ui || (function($) { //...

Which would cause the code to fail.

In JavaScript, a semi-colon all by itself has no syntactic value. The following two statements are the same:

//Statement 1
;;; ;; ; alert('hello world!'); ;;; ;; ;;

//Statement 2
alert('hello world!');
Andrew Moore
Huh, I didn't know that was valid JavaScript. +1
musicfreak