Skip to content

Comment on JavaScript: what is "this"?parent

Comments

Since the comparison happens before var is declared, it will always evaluate to 'true'. I believe the author was thinking about something like so:

    (function(name) { var cmp = function() { return name=="tim"; }; var name; return cmp();})("tim");
This still evaluates to true, but I believe it has to do with the rules of shadowing. If you change the declaration to 'var name="bob";' it will return false.
AboutSource Built by g1lg1l

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