JavaScript provides various ways to define and use functions. Two commonly used types of functions are anonymous functions and arrow functions. In ...
For further actions, you may consider blocking this person and/or reporting abuse
Nice!
It was help to me.
You are great.
I'm really happy this is helpful for you. Thank you so much for your feedbackπ
You are welcome.
Do you use discord?
No, I don't.
then,what u use for chat?
I'm active on X(twitter).
it was interesting to read! I wonβt be smart because Iβm just learning a little myself
Thanks for checking out, Andy!
Interesting fact: as soon as you assign an anonymous function to a variable - it ceases to be anonymous. Your example shows an anonymous function defined with a function expression, being assigned to a variable. After assignment, the function's name will be
myFunction- this can be checked by looking at the function'snameproperty:Checking the
nameof an actual anonymous function does what you would expect:Similarly, arrow functions are also anonymous (the two are not mutually exclusive as your post implies). They also have no name unless assigned to a variable:
An odd quirk with JS is that if you create a new function dynamically using the function constructor (
new Function()) - it is given the name 'anonymous' - which is a contradiction, since having a name at all makes it NOT anonymous! πMore fun with anonymous functions here:
Most Developers Can't Answer This Question About Anonymous Functions π€―
Jon Randy ποΈ γ» Mar 27 '23
Another point worth making is that if you intend to remove an event handler, it's not a good idea to use an anonymous function as in your example - as you will have no easy reference to the function available in order to remove the handler.