MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/onix79/javascript_function_facts/h5th96p/?context=3
r/learnjavascript • u/hsnice • Jul 19 '21
27 comments sorted by
View all comments
20
function declarations aren't the only thing that is hoisted, variable declarations with var are also hoisted.
var
e.g. the following does not work:
console.log('hello', future()); const future = function() { return ' world'; }
3 u/Claudioub16 Jul 19 '21 I'm new to programming, but I really dislike hoisting. Why would you want to hoist a function? 3 u/HashFap Jul 20 '21 This gives you more freedom on how you structure your files. You're not forced to declare functions on the top, and instead can have the most relevant code on the top which can make the code easier to read.
3
I'm new to programming, but I really dislike hoisting. Why would you want to hoist a function?
3 u/HashFap Jul 20 '21 This gives you more freedom on how you structure your files. You're not forced to declare functions on the top, and instead can have the most relevant code on the top which can make the code easier to read.
This gives you more freedom on how you structure your files. You're not forced to declare functions on the top, and instead can have the most relevant code on the top which can make the code easier to read.
20
u/[deleted] Jul 19 '21
function declarations aren't the only thing that is hoisted, variable declarations with
varare also hoisted.e.g. the following does not work: