MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/onix79/javascript_function_facts/h5yusvm/?context=9999
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? 7 u/toastertop Jul 19 '21 Functions called before they are declared, won't throw a undefined error. 3 u/Claudioub16 Jul 19 '21 Since I'm novice allow me to ask this question: wouldn't be a easy fix to just put the function before the call? 1 u/sateeshsai Jul 21 '21 flexibility. i prefer to keep all relevant functions grouped at one place.
3
I'm new to programming, but I really dislike hoisting. Why would you want to hoist a function?
7 u/toastertop Jul 19 '21 Functions called before they are declared, won't throw a undefined error. 3 u/Claudioub16 Jul 19 '21 Since I'm novice allow me to ask this question: wouldn't be a easy fix to just put the function before the call? 1 u/sateeshsai Jul 21 '21 flexibility. i prefer to keep all relevant functions grouped at one place.
7
Functions called before they are declared, won't throw a undefined error.
3 u/Claudioub16 Jul 19 '21 Since I'm novice allow me to ask this question: wouldn't be a easy fix to just put the function before the call? 1 u/sateeshsai Jul 21 '21 flexibility. i prefer to keep all relevant functions grouped at one place.
Since I'm novice allow me to ask this question: wouldn't be a easy fix to just put the function before the call?
1 u/sateeshsai Jul 21 '21 flexibility. i prefer to keep all relevant functions grouped at one place.
1
flexibility. i prefer to keep all relevant functions grouped at one place.
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: