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