News for hackers. Stuff that matters.
Re:What Elm and Haskell are teaching mainstream JS [video] by zipfle on Tuesday December 01, 2015 @02:56PM (#10658263)
JavaScript's scoping is much friendlier for creating closures than Python's:

    def why_is_scoping_hard():
        n = 4
        def print_n():
            print n
        def modify_n(new_value):
            n = new_value
            print n
        return [print_n, modify_n]

    >>> print_n, modify_n = why_is_scoping_hard()
    >>> print_n()
    4
    >>> modify_n(7)
    7
    >>> print_n()
    4
When you assign to a variable it is automatically created in the local scope, shadowing a variable with the same name from an outer scope. If you don't assign to it, you get the value from the outer scope. If you try to print it, but then assign to it later, the print call raises an error.
Re:What Elm and Haskell are teaching mainstream JS [video] by sophacles on Tuesday December 01, 2015 @04:35PM (#10658976)
Note - in python3 variable shadowing is much more controllable - in your example having modify_n look like:

    def modify_n(new_value):
       nonlocal n
(and of course the print x -> print(x) changes), will result in 4,7,7