The function expressions are all anonymous, but then they're given a name afterward.
Consider
function hof(fn) {
setTimeout(() => console.log(fn(5)), 1000);
}
hof(x => x * x);
You could argue that this is "more anonymous", but it's also assigned into a variable called fn. It's no less or more anonymous than const square = x => x * x;.
You could maybe use an IIFE to be "truly anonymous", but... this is just splitting hairs really. Any function expression is an anonymous function.
There are actually subtle differences between assigning a function to a variable and passing an anonymous function as a parameter. Assigning a function directly to a variable gives it a name (and the definition of an anonymous function is one that doesn't have a name):
function showName(x) { console.log(x.name) };
// Prints "square", because square is not in fact an anonymous function.
const square = (x) => x * x;
showName(square);
// Prints "", because this is an anonymous function.
showName((x) => x * x);
9
u/[deleted] Apr 14 '24
[removed] — view removed comment