picking arrow functions vs regular functions
Hey, i understand that picking whether to use arrow functions or regular functions is sometimes based off of preference but mainly based off of what behavior you'd like, however why are functions such as
setTimeout
mainly seen to use arrow functions not regular? e.g.
at first glance, there doesn't seem to be any more benefits to one than the other in this case so is this more of a personal preference one?
thanks in advance.15 Replies
I use them cause they're shorter
I use them because of the implicit return
The only difference i think is that you can return stuff more easily with arrow function, for example
also a very good reason
I do more functional programming so a short, one-line function with implicit return is almost always preferable for me
though with setTimeout I find myself often just writing the function and passing it in by reference
single line implicit returns are something I use more with array functions like map or sort or filter
And when using curried functions it doesn’t look as cluttered:
ah okay that makes sense, i appreciate everyone's opinions
Keep asking questions, I always have opinions! lol
i'll keep that in mind haha
i always prefer using the old-school variant because you can hoist and name them
for debugging, a named function is amazing
for example:
this means that, when you run the code and something bad happens, you will see
click_handler
instead of <anonymous function>
ah yeah that seems useful, can't you name arrow functions by putting them in a variable though?
that's not a named function
it's still an anonymous function
ah okay
My IDE offers an arrow function in the autocompletion whenever a callback is needed, so it's easier to just use that instead of deliberately overriding the suggestion.