Consider this code:
function x(){
console.log(y);
}
x();
var t = x();
console.log(t);
This will throw an error. But if you comment the first console.log inside the function, it will work and print undefined
.
What is the explanation of this behavior.
Thank you.