r/node • • Apr 14 '24

JavaScript Functions - 4 Ways

Post image
208 Upvotes

79 comments sorted by

View all comments

9

u/[deleted] Apr 14 '24

[removed] — view removed comment

8

u/BenjiSponge Apr 14 '24

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.

1

u/rover_G Apr 14 '24

The arrow functions also don’t have a prototype. What that actually means I’m not sure.