What is the benefit of using semicolon before a self-invoking function in JavaScript? I saw this approach in few popular jQuery plugins and I’m curious to find if this is the next awesome thing in JavaScript that I don’t know.
What is the benefit of using semicolon before a self-invoking function in JavaScript? I
Share
If you concatenate two files with self-invoking functions together that look like this:
File A:
File B:
File A+B:
You have two statements without separator. This happens when you cat files together and then minify them.
Now the author of file B puts a semicolon in front:
File B2:
And you’ll get a working script: