Lexical Binding

Describing Lexical Binding

  • Lexical scoping defines how variable names are resolved in nested functions
  • Inner functions contain the scope of the parent function

Illustrating Lexical Scoping

let o = (function() {
    let priv = () => "hello";
    return {id: 1, pub: priv()};
})();

console.log(o);  // {id: 1, pub: "hello"}

References

Previous

Default Binding