Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JavaScript Closures

Lean Machine
September 04, 2013

JavaScript Closures

Lean Machine

September 04, 2013
Tweet

More Decks by Lean Machine

Other Decks in Programming

Transcript

  1. for ( var i=0; i<5; i++ ) { // Wait

    i seconds then print // the number of seconds waited for each i }
  2. for ( var i=0; i<5; i++ ) { // Wait

    i seconds then print // the number of seconds waited for each i }
  3. Server JavaScript allows you to refer to variables that were

    defined outside of the current function Functions can refer to variables defined in outer functions, even a!er those functions have returned Closures can update the values of outer variables Three rules of closures