0

I would like to know which is the difference between these expressions:

case a:

const functionA = () => {
   executeA(), executeB()
}

case b:

const functionA = () => {
  executeA();
  executeB();
}
David
  • 208,112
  • 36
  • 198
  • 279
  • 3
    Personal opinion, but I'd say that the first one is just trying to be clever for no reason. The comma operator has a purpose, and its purpose isn't used there. Better to just invoke each function as its own statement for clarity. (If there's a linter configuration to warn on expressions with ignored results, I'd recommend enabling it.) – David Aug 22 '22 at 20:07
  • 2
    The first version is a way less readable way to do the same thing used by people who like to write "optimized" code. –  Aug 22 '22 at 20:07

2 Answers2

2

They do exactly the same thing, but the first one is weird and the second one is the normal way of writing code. Don't use the first version.

Guillaume Brunerie
  • 4,676
  • 3
  • 24
  • 32
1

The first one is an expression that uses comma operator

The other one is two statements.

There is no difference between these two in this situation.

Konrad
  • 21,590
  • 4
  • 28
  • 64