Someone sent me this pic on Discord saying Functions are hoisted first and then the variables.
prnt .sc/xdwc9a (please delete the space before dot, I dont want to spam)
His statement seems true cause the function is being invoked without throwing any error.
Kyle Simpson also says the same thing in his YDKJS book:
- bit .ly/39Wolka
However, when i experiment with it, I dont get what I expect. logger() // 10
function logger(){
var x = 10;
function x(){
console.log('Function code')
}
function x(){
console.log("more code")
}
console.log(x)
}
This returns 10 however since functions are hoisted first, x function should have been hoisted and in the second run of hoisting (which hoist variables) when it tried to hoist var x; it should've ignored it cus the function x was already hoisted but it doesn't seem like that's what happening here!
Am I missing something?