Results 1 to 4 of 4

Thread: semicolon usage?

  1. #1
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default semicolon usage?

    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.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    A semicolon would be necessary in situations like this:

    Code:
    var a = "foo";var test = "123 abc"
    it would also be legal to do this:

    Code:
    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.
    - Mike

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    There's a whole thread on the subject.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    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
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •