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?
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?
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!');