DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Haseeb
Haseeb

Posted on

What would this JS code print? πŸ€”

What do you think this piece of code will print? Most of you might know the answer but the behavior is really interesting to me and got me thinking and learning about a very important concept in JS.

function saySomething() {
    var greeting = "Hello";
    {
        greeting = "Howdy";
        let greeting = "Hi";
        console.log(greeting);
    }
}
saySomething(); //what would this print?

Top comments (3)

Collapse
 
invot profile image
invot • Edited on

error. It returns an error.
developer.mozilla.org/en-US/docs/W...

Collapse
 
swssr profile image
Simo

Console error I think invalid token.

Collapse
 
techie448 profile image
techie448

Interesting, could you help understand why it is throwing an error?

Your PRs make a difference 😍

We've got a great set of issues to modernize our JS management on the platform. Can you pitch in?