Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var hi = "hello"                          // Global
  2.  
  3. function grandparent () {
  4.   var one = 1                             // Private to `grandparent`, `parent`, and `child`
  5.   console.log( hi, one, two, three )      // hello, 1, undefined, undefined
  6.   parent()
  7.  
  8.   function parent () {
  9.     var two = 2                           // Private to `parent`, and `child`
  10.     console.log( hi, one, two, three )    // hello, 1, 2, undefined
  11.     child()
  12.  
  13.     function child () {
  14.       var three = 3                       // Private to `child`
  15.       console.log( hi, one, two, three )  // hello, 1, 2, 3
  16.     }
  17.   }
  18. }
  19.  
  20. grandparent()
  21. console.log( hi, one, two, three )        // hello, undefined, undefined, undefined
  22. console.log( grandparent, parent, child ) // Function, undefined, undefined