PDA

View Full Version : semicolon usage?



BLiZZaRD
10-28-2006, 02:16 PM
I have actually sat down and started learning this language. So far it isn't as hard as it first seemed, I actually think I might get a grasp on this!

I don't have any real questions with the lessons yet (I am sure I will when I get into objects and such...)

Anyway I was learning about the way to introduce JS into the page and all that, and the lesson said that semicolons after the ) are optional UNLESS there are more than one item in the string.

My question is, since I am just starting and basically don't have any "bad habits" is it customary to use the semicolon all the time, or just when it is needed?

To me, I would prefer to use them always, but at the same time I don't want to look like a dork when I post code to ask for help, or am actually helping someone else.

mburt
10-28-2006, 03:06 PM
A semicolon would be necessary in situations like this:


var a = "foo";var test = "123 abc"

it would also be legal to do this:


var a = "foo"
var test = "123 abc"

It's different then c++, or php, and yes, semicolons are optional. It doesn't look bad in code, sometimes even, it helps with reading code. It's completely up to you, unless you have a situation like the first one I showed.

Twey
10-28-2006, 04:36 PM
There's a whole thread (http://www.dynamicdrive.com/forums/showthread.php?t=10457) on the subject.

BLiZZaRD
10-29-2006, 08:48 PM
I saw that thread before and couldn't find it again. I blame vBulletin's searching abilities. :)

I know about the use of semicolons in the places it is required I was just curious as to the use of the nonrequired places.

I think the consensious is to go ahead and use them though. I was just checking :D