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?
No description
3 Replies
13eck
13eck•11mo ago
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:
const myFunc = function() {
console.log(“Function fired!”);
}
const myFunc = function() {
console.log(“Function fired!”);
}
As it’s a variable and not a “top level” function it’s not hoisted.
Killer🔪
Killer🔪OP•11mo ago
Okay, thanks alot @thevanilla13eck. Learnt a new thing today
Zoë
Zoë•11mo ago
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.
Want results from more Discord servers?
Add your server