Search code examples
javascriptstrict-mode

can local variables inside a sealed object pass information to global variables?


Not sure if I'm wording this correctly but can local variables inside a sealed object pass information to global variables?


Solution

  • Yes, they can:

    var hello = 0, obj;
    
    obj = {
      foo: function () {
        hello = 3;
      }
    };
    
    Object.seal(obj);
    
    console.log(hello); //logs 0
    obj.foo();
    console.log(hello); //logs 3
    

    Here's a jsfiddle.