Introduction
William Shakespeare once said that “What’s in Name?” but as a developer, we can disagree. We have to name variables, classe...
For further actions, you may consider blocking this person and/or reporting abuse
A lot of confusion and incorrect information in this article. Many of your 'anonymous' functions are not anonymous functions at all
If you read the article, it's for storing the function in a variable.
This is not correct - you can declare a named function without a function statement, and immediately invoke it:
It is true that you cannot immediately invoke a named function created with a function statement, but not true that you cannot invoke a named function immediately after declaration.
Immediate invocation is possible because the preceding code is an expression whose value is a function - it has nothing to do with whether the function is anonymous or not. If you have defined a function using a function statement - then that statement is not an expression and therefore has no value that you can call.
Considering this, I like to thank you as I was not having the knowledge on this. I have updated the article as per your feedback.
Yes, but the very act of assignment makes those functions cease to be anonymous functions. They acquire the name of the variable/constant. This can be shown by checking the function's name:
Contrast this with an actual anonymous function:
After the initial declaration of the anonymous function, it can't be invoked later. For that, we have to store it inside a variable. That's I did above. This has led to having a name.
There are a number of mistakes in this example. Firstly - it won't run because
myFunction()should say justfunctionorfunction myFunction(). Further,consoleis misspelled and the message will display after 1 second, not one minute.Typo fixed.