0

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?

  • 1
    Not quite sure what you're asking, but it seems you are confused by [`window.name` not being `undefined`](https://stackoverflow.com/q/30027902/1048572) – Bergi Sep 04 '22 at 20:53

0 Answers0