News for hackers. Stuff that matters.
Re:Show HN: NodeScript- JavaScript Without the Variable Decl... by clusmore on Monday February 20, 2017 @07:32PM (#13692259)
How does this handle shadowing? Consider, for example,

  let x = 1;
  function foo() { let x = 2; }
  function bar() { x = 3; }
  console.log(x); // 1
  foo();
  console.log(x); // 1
  bar();
  console.log(x); // 3
Without the declaration, how can you tell whether I intend to shadow or not?

Edit: I note from another comment that you state

> If you want to make a global variable, you will have to explicitly write it as a property of the global object.

The example above could appear in any scope, not only the global scope. Python now has a `nonlocal` keyword (as well as the `global` keyword) to disambiguate these cases.

Re:Show HN: NodeScript- JavaScript Without the Variable Decl... by pretodor on Tuesday February 21, 2017 @04:10AM (#13694346)
The default behaviour is not to shadow variables. If you want to shadow a variable, you have to do so explicitly with the 'let' keyword.

Here is a NodeScript snippet and its equivalent in Python:

    // NodeScript
    
    x = 10
    function outer() {
        y = 20
    
        function inner() {
            x = 100
            y = 200
        }
    
        inner()
        console.log(x, y)
    }
    
    outer()


    # Python
    
    x = 10
    def outer():
        y = 20
    
        def inner():
            global x
            nonlocal y
    
            x = 100
            y = 200
    
        inner()
        print(x, y)
    
    outer()