-1

I have a question. What is the different between the async message and only (message). Here is an example with the async client.on('message', async message => {CODE}

And here is an example without the async client.on('message', (message) => {CODE})

I hope you can understand my question ;)

  • The parenthesis around the parameter of the arrow function can be omitted if there is exactly one parameter. `(message) =>` === `message =>`. – Ivar Aug 20 '20 at 08:29

1 Answers1

0

(message) => {} is an arrow function and async message => {} is an async function

The essential difference is that in an async function you can await for asynchronous code completion.

And as you can read in mdn page for arrow function expressions:

// Parentheses are optional when there's only one parameter name:
(singleParam) => { statements }
singleParam => { statements }

so

async message => {CODE}
// is equal to
async (message) => {CODE}

and

(message) => {}
// is equal to
message => {}

What's important is to be consistent in the way you use parentheses, and the best way to achieve 100% consistency in your code is to use a tool like prettier.

marzelin
  • 10,790
  • 2
  • 30
  • 49