Arrows function can't be hoisted?
I saw this comment on a post on X. I know that functions are hoisted to the top but I have no idea about arrow functions.
Are they really not hoisted to the top?
3 Replies
No they aren’t. Arrow functions are assigned to a
const
as a normal variable. Variables aren’t hoisted, only functions made with the function
keyword.
Same goes for a function declared like this:
As it’s a variable and not a “top level” function it’s not hoisted.Okay, thanks alot @thevanilla13eck.
Learnt a new thing today
I have a problem with the Twitter user saying it’s a problem. I’ve done a lot of functional programming and functions in the ones I’ve used aren’t hoisted at all, you can only refer to things above the current line and above the current file. What you end up with is far easier to read files you just go too to bottom and you never need to peek a definition.
If you have all of the abstraction at the top you’re left with loads of questions that requires jumping around to answer.