in reply to Re^3: Closures and scope of lexicals
in thread Closures and scope of lexicals

I was referring to his first example which prints 123

That's more complicated to achieve in Python IMHO.

Edit

I think JS had a similar effect with var , that's why let was introduced

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^5: Closures and scope of lexicals
by ikegami (Patriarch) on Oct 31, 2024 at 14:38 UTC

    Yes, JS's var is function-scoped at the narrowest. It's even retroactive such that

    foo = 1; var foo;
    is equivalent to
    var foo; foo = 1;
Re^5: Closures and scope of lexicals
by ikegami (Patriarch) on Oct 31, 2024 at 14:35 UTC

    I didn't translate the first snippet. The question is about the second snippet. The OP asked if its behaviour is a quirk. I showed that it's not by showing that the behaviour is consistent across many languages.

        Then you're wrong. The provided code is equivalent to the OP's, and the result is consistent.