Arrow functions vs named arrow functions

I am presently at step 11 of “Learn Basic String and Array Methods by Building a Music Player”. So far, there is no problem, but I am having difficulties getting my head around the following apparent contradiction. I quote from step 11:

An arrow function is an anonymous function expression and a shorter way to write functions. Anonymous means that the function does not have a name. Arrow functions are always anonymous.

And a few lines down:

To create a named arrow function, you can assign the function to a variable …

always anonymous <=> named arrow function

So I would lean towards a broader formulation and say: “are usually anonymous, but can be assigned a name”.

So what is it I do not understand?

(I am not asking for help with this specific step 11, at least not yet :wink: )

edit 2024-07-13–090700

In step 12 now I am even asked to “call a named arrow function” which to me looks exactly like any other function call:

printGreeting();

Hey, I believe they say that arrow functions are anonymous because it’s not really the arrow function that has a name but more the variable that is assigned to it.
However, it’s just a hypothesis. Nevertheless, I believe it makes sense.

Yes I see what you’re saying. However they are not wrong. All functions are called the same way, with parenthesis like () but arrow functions are different because they don’t need a name (in fact they are “always” anonymous) but you can store them in a variable so you can have a way to handle them that is a bit easier to read. But if you didn’t” give them a name “by storing them in the variable then you would do this to invoke the function:
( () => {} )();
The last two parentheses are calling the anonymous function. Without a handle, this is how you would invoke them immediately after declaring them. However, if you don’t invoke them right away or store them somewhere (like in a variable) then you won’t be able to call them after declaring them.

Thank you for your reply :slight_smile:

If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck.

But what exactly is the decisive difference?

function myFunc() {};

const myFunc = () => {};

Both I will call with:

myFunc()

@hbar1st

Just read your reply now (Thanks :slight_smile: )

I understand you like this: these are two, possibly three ways (“named anonymous function”) to write a function? The “proof is in the eating”?

Yes there are multiple ways of writing a function. You have learned two so far which are the most common I believe.

You can read about another way here:

Thanks, this is enough food for thought. If at all possibly, it would be very useful to have a use case where you can only one or the other …

I suggest that you wait until you have covered more of the curriculum to look up an answer to this. There are articles and documentation that will show you the differences and usages. In short: arrow functions have limitations that regular functions do not.