In the last months I wrote a lot of code in node red for my home automation and even if I am a beginner, it's work fine.
I also copied a lot of code from this forum but sincerely I didn't understand the proper use of comma and semicolon into a function,
Probably sometimes are necessary, sometimes not but I'd like to know the specific use ....
example n 1: at the end of every line need semicolon or not?
...
var x = msg.payload;
flow.set("var_ora_onmill" ,x);
flow.set("var_lavatriceon" ,1);
...
exampe n 2: at the end of every line (msg) need comma or not? (or need semicolon?)
...
if (x == 0)
{
msg.labelcolorbloc = "white"
msg.bgcolorbloc = "red"
msg.labelbloc = "STOP"
return msg;
}
...
example n. 3: at the end of every line (msg) need semicolon?
You will find that the standard style now more often omits ; rather than includes them. There are a couple of places you might need them but generally, they are no longer needed at all. So I disagree in general with the warning from that article (which is from 2018 and JS has move on a long way since then).
No, because each of those lines is a statement in its own right. If anything, you would use a ; (but really you don't need to).
You need comma's when you specify an OBJECT, not a statement:
const myObject = {
'property1': 'I am the value of property1',
'property2': 'I am the value of property2',
}
Note that trailing commas are permitted in JavaScript Objects and personally I recommend them because it makes it a lot easier if you need to re-order the lines or add a new property/value pair.
The other place you might use a comma in a statement is if you want to define multiple variables - personally I generally avoid this. Again because it is prone to mistakes and they can be hard to find because they are hard to read:
let x,y,z
No for the same reasons as the first response.
Another pet peeve of mine is the C-style brackets use (having the bracket on a separate line as you have done). I guess if you are used to C/C++ that is the common style but I dislike it because it pulls the eye away from the logic structure (in my view anyway). It also uses up extra lines on-screen which often means that you have to scroll more to see the code. This all wastes time and is a distraction.
Absolutely. All I can say is that StandardJS wouldn't have taken off as much as it has if it weren't a decent option.
When I'm writing JavaScript, I'm using VScode with ESLint set to StandardJS with a couple of tweaks. For example, I don't like double-quotes around strings - for 2 reasons: 1 is that single-quotes don't require a shift-key to type whereas double-quotes do (at least on a UK keyboard) and The extra pixels can be visually distracting (there's my OCD again ).
Anyway, ESLint tells me if I need a ; somewhere - but it never has done, ever.