Hacker News new | ask | show | jobs
by afandian 2807 days ago
Not GP but variable scope in JS is very different to e.g. C, C#, Java etc. Superficially it appears similar, but the syntax is a faux amis.
2 comments

JS's scope is really weird

    for (let i = 0; i != 3; i += 1) {
        console.log(i); // i refers to the variable defined below
        const i = 0;
    }
Is is very similar to Lisp, Clipper or Perl, also known in CS circles as dynamic scope variables.
I've never come across hoisting in another language (not that I've looked hard).
I gave you a couple examples, though.

And here is another one, upvar in Tcl.