Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use semicolon? [duplicate]

Are there any reasons, apart from subjective visual perception and cases where you have multiple statements on the same line, to use semicolon at the end of statements in JavaScript?

It looks like that there's plenty of evidence suggesting that use of semicolons is highly optional and is required in only few of the specific cases.

like image 537
Art Avatar asked Mar 08 '10 07:03

Art


People also ask

What does double semi colon mean?

A "double semicolon" does not have any special meaning in c. The second semicolon simply terminates an empty statement. So you can simply remove it.

Can you use semicolons twice in a sentence?

Yes, semicolons can be used to connect three, or more, related independent clauses. That was fairly common a few hundred years ago, but it became less common as literacy spread.


1 Answers

Because JavaScript does nasty things to you when it guesses where to put semicolons. It's better to be explicit and let the interpreter know exactly what you meant than it is to let the idiot box guess on your behalf.

References:

  • http://www.webmasterworld.com/forum91/521.htm
  • http://www.howtocreate.co.uk/tutorials/javascript/semicolons
  • http://robertnyman.com/2008/10/16/beware-of-javascript-semicolon-insertion/

...and a cast of thousands.

like image 101
JUST MY correct OPINION Avatar answered Oct 05 '22 03:10

JUST MY correct OPINION