Skip to content

Comment on Hide this in your coworkers' JavaScript code tomorrowparent

Comments

I'm not too sure either. In JS, block scoping does not exist. There are only function scopes, so the var declaration gets hoisted out of the if block (but the assignment occurs in the if block - so the assignment doesn't happen).

Oh you can definitely fake block scoping in JavaScript, with ES5. ;P

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.