Is this an arrow function declaration? Is there such a thing?

219 views Asked by At

I am looking into function expressions vs function declarations using arrow functions.

I am thinking this is an arrow function expression:

const johan = greeting = () => {
  console.log("Hi from arrow function expression");
};

and that this is an arrow function decleration:

 ludwig = () => {
  console.log("Hi from arrow function declaration");
};

Is that correct? Or maybe there is no such thing as an arrow function declaration? Maybe there is only arrow function expressions?

If so, what is it called when I put a named arrow function expression in another variable?

Happy for any answer! :)

1

There are 1 answers

0
Quentin On BEST ANSWER

No.

There are function declarations, function expressions, and arrow functions (the syntax which creates them also being an expression).

(There are also method declarations which can use arrow functions.)

ludwig = () => {
  console.log("Hi from arrow function declaration");
};

This is assigning a value (an arrow function) to a variable.

The variable declaration is missing, so either it appeared earlier or this creates an implicit global (which is forbidden in strict mode).