When it is mandatory to use Javascript point and comma

Asked

Viewed 884 times

2

I wanted to know when it is mandatory to use a point and comma in Javascript.

  • One is more open to opinions, in the other there is the obligatory character.

1 answer

5

Still the use of the semicolon is mandatory when using the loop for and when the line you follow starts with any of these you must finish the semicolon command: ([+-/* [source]

In most cases, it should also be used when using more than one instruction on the same line. There is the exception of several instructions within an expression, in which case commas can play the role of semicolons:

if (condição) faça_isso(), e_também_isso()
  • 1

    Also if you want to have two expressions on the same line. And to separate the command parameters for.

  • Good practice is to use always.

  • Each one follows its own style: I’ve seen projects on Github that they prefer not to use. I will not stop collaborating but also I will not reach him and impose my style: only know the implications of using it.

  • Yeah, but Douglas Crockford’s jslint is the widely accepted standard for "good Javascript" and it charges semicolons. Said author shows situations where the lack of ; leaves the code ambiguous.

  • I don’t think this is "grammarian versus linguist" because Crockford wouldn’t be a grammarian. He’s just radical (and that’s why I can’t agree with everything he says).

  • Okay, I removed my comment because my comparison was very radical: grammarians do not compare to him.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.