4 ms·
4 ways
by wvenable 2y ago
4 ways
- Izkata 2y ago5 ways, the arrow functions have two different syntaxes: () => { return 1; } () => 1
- wiseowise 2y agoThat’s still one way - arrow function.
- Izkata 2y agoWell, these have the same result, so if the two types of arrow functions don't count as different then neither should these two assignment versions: const foo = (function() {}).bind(this); const foo = () => {}; Edit: And speaking of assignment versions, there's a new comment that adds a third of the same. I kinda get the feeling a lot of the "multiple ways to declare functions" is just people who don't understand how the pieces of javascript fit together and think these are all independent. They're not. Just declaring a function has only a few ways, but declaring a function and giving it a name multiplies that out to some extent. In javascript, functions are first-class objects: they can be assigned to variables and passed around just like numbers or strings. That's what everything except "function foo() {}" is doing.