I often encounter this:
;(function (window) {
// ...
}(window);
I know that this anonymous function is called providing the window as the scope. But why is there a semicolon before it? I have never used that myself.
I often encounter this:
;(function (window) {
// ...
}(window);
I know that this anonymous function is called providing the window as the scope. But why is there a semicolon before it? I have never used that myself.
By putting it there, it ensures the preceding statement was closed. It's particularly important when you are minifying JavaScript code. One of the most common problems there is when you don't have one file that ends with neither a new line nor a semicolon and gets merged with one that starts with neither. That effectively merges the last statement of the first file with the first line of the second file resulting in syntax errors.