0

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 Answers1

2

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).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Very interesting (regarding the strict mode as well), thanks for the answer and thanks for the links, will read in on them! Thanks to all you answering! – Johan Berglund Dec 08 '20 at 12:40