tags:

views:

80

answers:

4

Hi ,

I missed semicolons in some of the places in my javascript , but its not throwing error in any of the browsers. Do the : at the end needed for sure

A: 

If it's not throwing compiler errors, you should be fine. It's better that you do remember to use them all the time however, as some languages that you might get into such as objective-c are adamant about their use.

XenElement
remembering a syntax rule in one language doesn't have any benefit toward other languages.
TokenMacGuy
But the rule of a semicolon is so universal that in general remembering it has many benefits.
XenElement
+7  A: 

The concept is known as JavaScript Semicolon Insertion or "Automatic Semicolon Insertion". The blog post JavaScript Semicolon Insertion: Everything you need to know outlines it well in an understable manner using examples:

  • Where Semicolons are Allowed
  • Where Semicolons May be Omitted
  • The rules

It evens digs into the official ECMAScript specification about the topic.

John K
Thanks john very much
gov
+2  A: 

Javascript does something called "semicolon insertion" which means you can actually write code that omits the semicolon in certain places, and they'll basically be added for you when the code is parsed.

The rules around when this happens a little complex. For simplicity's sake, many developers simply pretend semicolon insertion doesn't exist.

ShZ
Thank...you all..i got it.
gov
Sometimes I fantasize about a world where semicolon insertion doesn't exist.
Alex JL
There was an interesting thread recently on the node.js mailing list that's worth a read: http://groups.google.com/group/nodejs/browse_thread/thread/3166a2bd54e2acf6?pli=1. Check out Isaac Schlueter's coding style; it's an interesting way to take advantage of ASI -- it's not necessarily a bad thing :)
ShZ
+1  A: 

Semicolon is not required for javascript programming nevertheless i advice you to use it, it makes your code more readable and is actually a good practice almos all cool Programming languages use it.

So take a stand and use it, its up to you now!!

Necronet
It's not true that semicolon is not required. From the spec: `Certain ECMAScript statements **must** be terminated with semicolons.` http://bclary.com/2004/11/07/#a-7.9
John K
yes you are right i clarify thanks to Automatic Insertion there are many cases you are entitle to avoid it but(a big BUT) as i said before i dont think is good practice to do it
Necronet