0

I have been looking at some JavaScript libraries and I came across one library that began like this:

; (function(){
    //library code
})()

Why is there a ; before the anonymous function? There was no code before this.

George Stocker
  • 57,289
  • 29
  • 176
  • 237
Progo
  • 3,452
  • 5
  • 27
  • 44
  • 4
    this will ensure that a concatenation of multiple js files into a single file won't throw an error if a previous statement misses a `;` – Fabrizio Calderan Jan 14 '14 at 13:30
  • 1
    This is a pretty ridiculous trend. Files should just concatenated correctly instead of doing stupid things like this. – Jeff Shaver Jan 14 '14 at 13:33
  • @JeffShaver I completely agree. If only we lived in a perfect world :-) Unfortunately these are the kind of things that slip into habit, and might still be common in 20 years when all JS file concatenation tools have been fixed and nobody really remembers why we do it. – CompuChip Jan 14 '14 at 13:33
  • @CompuChip hopefully not xD My recommendation to the OP would be to avoid this trend. – Jeff Shaver Jan 14 '14 at 13:38

0 Answers0