Always use semicolons in JavaScript

Posted on in JavaScript

According to Javascript; the semicolon after a statement (for example a function), is optional.
However, it's much better to end your line with a semicolon. A validator like JSLint for example, will throw a warning, even though
the browser won't and accepts it.

See below, which strange things can happen when you won't end your line with a semicolon.
Javascript errors because of the order of javascript functions mixed with jQuery plugins...

foo is a simple javascript function.
Baz is a simple self running jQuery plugin. (because of the parentheses surrounding it).

foo = function(){
alert("function 1"); 

$.fn.Baz = function(opt){
alert("function 2");

See below the script, without strange javascript errors.

The answer is really logical.
Because there is no semicolon, the jQuery plugin (Baz) will directly execute, because of the parentheses.
Like it's a parameter of the javascript function you wrote before. (foo), and then throws errors.


When you mix your jQuery plugins with native javascript classes and functions in different orders; these kind of errors can happen.
This scenario above shows you why you should always end your statements with a semicolon.

viagra for sale viagra dosage viagra alternatives how does viagra work cyalis generic cialis cialis for sale cialis coupons side effects of viagra viagra pills for sale viagra prices without insurance cialis generic cialis pills for sale viagra savings offer viagra canada canada viagra over the counter viagra cialis cialis side effects generic for cialis cialis sample viagra coupons 75 off cialis 20mg is viagra covered by insurance online viagra viagra substitute cialis without a doctor's prescription buy cialis female viagra cialis 5mg daily free cialis viagra vs cialis vs levitra viagra coupons canada cialis cialis 5 mg cialis savings card cialis coupon cialis dosage recommendations viagra government funding generic levitra levitra vs cialis pfizer viagra coupons utilisation viagra cialis trial sildenafil vs viagra levitra vs viagra for hardness 200 cialis coupon online cialis how much does cialis cost cialis copay card cialis dosage strengths levitra online cialis coupons 2017 cilias cialis effects daily cialis inexpensive viagra pills cost of cialis levitra women viagra generic viagra 100mg how much does viagra cost levitra 10 mg cialis cheap viagra single packs cost natural viagra buy viagra cialis otc cvs pharmacy viagra coupons walgreens viagra substitute viagra vs cialis cialis coupons printable levitra coupons free viagra stendra vs viagra cialis coupons from manufacturer cialis voucher levitra 10mg viagra from amazon buy viagra online levitra without a doctor prescription cialis free trial levitra vs viagra trial viagra sample canadian cialis is viagra government funded in america viagra pill cialis from canada cialis professional otc viagra levitra coupon cialis coupon print cialis pills cialis vs viagra levitra generic what is levitra viagra cialis cialis discount wholesale cialis viagra prices erectile dysfunction cialis sex viagra for women side effects of cialis does the government fund viagra cialis testimonials viagra coupons from pfizer cialis canada viagra single packs cialis generic availability cialis patent expiration date extended cialis samples overnight cialis for bph pfizer viagra lowest cialis prices cost of viagra levitra prices how long does levitra last generic for viagra female viagra pills viagra without a doctor prescription usa cialis on line generic cialis tadalafil cialis coupon 20 mg viagra discount viagra viagra generic cialis patent expiration viagra activate non prescribed viagra viagra coupon cialis canadian pharmacy buy levitra levitra vs viagra viagra on line revatio vs viagra is viagra federally funded cialis vs viagra levitra reviews viagra pills liquid cialis cialis medication generic cialis at walmart 9 levitra at walmart cialis dosage cealis viagra patent expiration discount cialis viagra 100mg price walmart buy cialis online cialis for daily use cialis samples viagra vs cialis cost of levitra how to take cialis what does viagra do cialis website viagra price viagra for women cialis prices does viagra work cialis 5mg viagra without prescription viagra side effects levitra loc us viagra porn levitra side effects viagra without a doctor prescription canadian viagra cialis daily viagra cost viamedic cialis cialis 30 day sample levitra dosage price cialis levitra 20 mg sophia viagra what is viagra when will cialis go generic how long does viagra last cialis generic tadalafil levitra cost buy levitra online cialis or viagra cialis reviews cialis cost viagra best price generic viagra where to buy viagra viagra samples viagra pharmacy cialis or viagra order online viagra viagra costs cialis alternative cialis 30 day trial coupon viagra dose viagra on line no prec cialis 10 mg is viagra government funded cialis pharmacy prices generic viagra available in usa levitra 20mg how does cialis work natural viagra alternatives that work cialis 20 mg cialis 20mg directions viagra 100mg tablets retail price cialis for men cheap viagra cialis online healthy man viagra levitra canada viagra sex viagra from canada is viagra funded by government viagra girls cialis pricing herbal viagra cialis price cialas cialis tadalafil viagra online cialis for women cialis patent expiration 2017 best price viagra what is cialis cheap cialis levitra 20 mg cost walmart viagra government funded viagra ingredients viagra vs cialis vs levitra