In JavaScript, when we talk about hoisting, the JavaScript engine moves the variable declarations to the top of the script. for eg:
console.log(name);
var name="xyz";
It gives output as undefined. Because the compiler reads it like:
var name;
console.log(name);//undefined
name=xyz;
But when we write the same thing in code editor, it executes the output. for eg-
var name;
console.log(name);
name=xyz;
output- xyz
The question is when we write the above code in code editor like vs code, why it did not print undefined in browser? Why it printed the output?