Possible Duplicate:
What does the leading semicolon in JavaScript libraries do?
I am reading the jquery flexslider source code and i see a ;
before the document ready call
;(function ($) {...
Can anyone tell me why we need a ;
?
Possible Duplicate:
What does the leading semicolon in JavaScript libraries do?
I am reading the jquery flexslider source code and i see a ;
before the document ready call
;(function ($) {...
Can anyone tell me why we need a ;
?
This is just to protect against any previous code lines that might be missing a semicolon.
If you know that the code before has a semicolon at the end, this semicolon is not needed at all.
It's included in case...
the code gets grouped into the same file with other code, and
the other code didn't include a semicolon at the end.
For example...
(function() {
// some bundled plugin
})() // <--- no semicolon
// v--- semicolon saved the day
;(function ($) {
// flexslider plugin
})();
Without the semicolon, the ()
around the flexslider plugin would have been interpreted as a function call, and would have tried to call the return result of the previous function.
This is not a typo. ;
prevents javascript errors in compliled/minified/compressed files. For example when several independent libraries/plugins get compressed together.