I have a file jquery.flex.js
which starts with
What does beginning mean?
I have a file jquery.flex.js
which starts with
What does beginning mean?
The purpose of this semicolon is to avoid an error if the file is concatenated with another one.
For example suppose you have two files like this :
(function(){
...
})()
It's OK as long as it's in two separate files but it's a error if you concatenate them as is frequently done to reduce the number of requests. What happens is that basically you have
(A)()(B)()
and that the engine is trying to call the result of (A)()
with argument B
.
Adding a semicolon to delimit the statements fix the problem.
Since most modules start with a self-executing function (function() {/* module code */}())
the trailing semicolon is just a security issue:
Take this example: if you load two js modules on your website, and the first one ends without a semicolon:
(function firstModule (window, undefined) {
/* whatever this module does comes here */
})()
and the second one looks the same:
(function secondModule (window, undefined) {
/* whatever this second module does comes here */
})()
Then you got a problem. Because your first module will execute itself and the second module will try to execute the result of the first modules self-execution:
(firstModule)()(secondModule)()
This would mostly break your code, or at least lead to unexpected behaviour.
So it is a simple pattern to add a leading semicolon to your module code:
;(firstModule)();(secondModule)()
And everything is fine.
I don't know what you're asking for, but your title says:
What does comma mean in javascript?
It is used as a separator.