Let’s talk anonymous functions and make them, well, “not anonymous”.
Anonymous functions are just function expressions. Let’s see a quick example.
The following code block has a ‘named’ function.
We can rewrite the same as an anonymous function and get the same end result.
“Normal” functions get parsed at the compile time, regardless of whether they are used or unused.
Wot? But, this is similar arrow functions?
Yes, and no.
Here’s an arrow function.
The only three differences -
- arrow functions can be named while anonymous functions wish to stay unnamed
- more importantly: anonymous functions have their own
thiscontext and arguments object while arrow functions inherit from parent/scope
- arrow functions cannot be called with
For all practical purposes I just use arrow functions and call it a day.