Depending on the tool used, this can happen. Imagine two .js files:
a.js
(function() { var bar = 10; }())
b.js
var foo = 5; alert(foo);
Both will work separately, but if you pack them together, this will not work anymore:
(function() { var bar = 10; }())var foo = 5;alert(foo);
obviously because it is absent ; . A good template to avoid this is to run each javascript file with ; , eg:
fixed a.js
;(function() { var bar = 10; }())
fixed b.js
;var foo = 5; alert(foo);
Output
;(function() {var bar = 10;}());var foo = 5;alert(foo);
Everything is clear, thanks!
jAndy source share