Need clarity about when to use commas and semi-colons in JavaScript

Hi,
please why do we place a comma(,) sometimes in JS instead of semi-colon(:wink: at the end of a sentence/expression in code. ?

I updated your topic title to reflect your question.

Do you have some example code section you can post and then tell us what confuses you specifically?

Hi,
i just need to understand the difference in why in some end of statement/ expression we use a comma(,) not a semi-colon(;). like in css we put semi-colon all through out 
This an example
"artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [
      "CD",
      "8T",
      "LP" ,
thank you

that is wrong syntax on its own

the only way for that to be value if it was a series of key-values couples in an object, like
{key1: "value1", key2: "value2"}

usually commas separate values in a list, and semicolons mean ends of expression

Just as a rule…

Semicolons are used at the end of lines or, more accurately, at the end of statements. (You could in theory have more than one statement on a line, though you usually don’t.) Though some people leave these off and the compiler inserts them for them (as long as you don’t have more than one statement on a line). So, some people will purposefully leave them off. You will hear arguments about whether to use semicolons or not.

But you don’t normally do it after a code block.

You also use semicolons to separate the expressions inside a for loop.

Commas are used to separate elements in an array or properties in an object. There is also a comma operator:

let  a = 1, b =2;
console.log(a);
// 1
console.log(b);
// 2

That kind of thing is not unusual to see.

This works:

**let x = (12, 15);
console.log(x);
// 15

let y = (++x, ++x + 1);
console.log(y);
// 18

But doesn’t get seen much, thank goodness.

Don’t worry about it too much. You’ll make some mistakes - that’s OK. In general, if you’re inside an array or object use commas - if it’s the end of a statement, then a (usually debatably optional) semicolon, or inside the definition of a for loop, those are semicolons too.

oka…y thanks for the clarification.

Thank you.................................. :smile: