Announcement

Collapse
No announcement yet.

Javascript: Semicolons or Not?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Javascript: Semicolons or Not?

    In parallel, I'm taking a javascript (browser centric) and a NodeJS course online. In the javascript course, the instructor is using semicolons at the end of every statement while in the NodeJS course, the instructor isn't using any semicolons.

    I found this, but that's only one person's opinion. I'd like to get input from the community on this.
    "if I have seen further [than others], it is by standing on the shoulders of giants." --Sir Isaac Newton (1675)

    #2
    As a Java developer, in general, the semicolon terminates the statement with a few exceptions.
    HS3PRO 3.0.0.500 as a Fire Daemon service, Windows 2016 Server Std Intel Core i5 PC HTPC Slim SFF 4GB, 120GB SSD drive, WLG800, RFXCom, TI103,NetCam, UltraNetcam3, BLBackup, CurrentCost 3P Rain8Net, MCsSprinker, HSTouch, Ademco Security plugin/AD2USB, JowiHue, various Oregon Scientific temp/humidity sensors, Z-Net, Zsmoke, Aeron Labs micro switches, Amazon Echo Dots, WS+, WD+ ... on and on.

    Comment


      #3
      Originally posted by langenet View Post
      As a Java developer, in general, the semicolon terminates the statement with a few exceptions.
      In Java, the semicolon is required as a command separator, just like it is in C. In Javascript it seems to be optional and since NodeJS is javascript it is optional there as well. After doing some research and finding cases where javascript may not do what is expected without semicolons, I've decided to use semicolons for both browser-centric and NodeJS coding. I liken this to adding parenthesis around expressions to make it clear how the expression is to be evaluated.
      "if I have seen further [than others], it is by standing on the shoulders of giants." --Sir Isaac Newton (1675)

      Comment


        #4
        I'm tied to using the semicolon... I think I remember now that you mention it that in Javascript, it was optional. Haven't done a lot of Javascript for a few years. Either way, you can't go wrong.
        HS3PRO 3.0.0.500 as a Fire Daemon service, Windows 2016 Server Std Intel Core i5 PC HTPC Slim SFF 4GB, 120GB SSD drive, WLG800, RFXCom, TI103,NetCam, UltraNetcam3, BLBackup, CurrentCost 3P Rain8Net, MCsSprinker, HSTouch, Ademco Security plugin/AD2USB, JowiHue, various Oregon Scientific temp/humidity sensors, Z-Net, Zsmoke, Aeron Labs micro switches, Amazon Echo Dots, WS+, WD+ ... on and on.

        Comment

        Working...
        X