console.log(window.b,b) //undefined undefined
if(true){
console.log(b) //ƒ b(){} does it get hoisted?
b = 4
function b(){}
b = 3
console.log(b) //3 Why is this variable 3
}
console.log(window.b,b) //4 4 Why is this variable 4
If the code removes this line
function b(){}
The browser will report an error VM114:1 Uncaught ReferenceError: b is not defined
at line 1 console.log(window.b,b)
Can someone tell me why it works like this??
if function b
gets hoisted, does it equals to
console.log(window.b,b) //undefined undefined why it doesn't cause an ReferenceError b is not defined
if(true){
function b(){}
b = 4
b = 3
console.log(b) // 3
}
console.log(window.b,b) // ƒ b(){} ƒ b(){}
I am not a native English speaker,hope you can understand.