This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var box = {}; | |
| box['innerBox'] = {}; | |
| box['innerBox']['full'] = true; | |
| box['innerBox']['height'] = 10; | |
| //do it here | |
| box.otherBox = {}; | |
| var innerBox2 = "otherBox" | |
| box[innerBox2].full = false; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var g = 'global'; | |
| function blender(fruit) { | |
| var b = fruit; | |
| var y = 'yogurt'; | |
| function blend() { | |
| alert(b + ' and ' + y +' makes ' + b + ' swirl '); | |
| } | |
| blend(); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | //Closure Example | |
| var closureAlert = function() { | |
| var x = 0; | |
| var alerter = function() { | |
| alert(++x); | |
| } | |
| return alerter; | |
| }; | |
| // funcStorer is the closure | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | //Lamba | |
| var closureAlert = (function() { | |
| var x = 0; | |
| var alerter = function() { | |
| alert(++x); | |
| } | |
| return alerter; | |
| }()); | |
| // calling itself with a closure | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var add = function(num){ | |
| var num1 = num; | |
| var addToNum1 = function(num2){ | |
| return num1 + num2; | |
| } | |
| return addToNum1; | |
| }; | |
| var add5 = add(5); | |
| add5(2); // 7 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var add = function(num){ | |
| var addToNum1 = function(num2){ | |
| return num + num2; | |
| } | |
| return addToNum1; | |
| }; | |
| var add5 = add(5); | |
| add5(2); // 7 | |
| add5(3); //8 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function counter() { | |
| var n = 0; | |
| return { | |
| count: function() {return ++n; }, | |
| reset: function() {n = 0;} | |
| } | |
| }; | |
| var myCounter = counter(), num; | |
| myCounter.count(); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var nonsense = function(string){ | |
| var blab = function(){ | |
| alert(string); | |
| }; | |
| setTimeout(blab, 2000); | |
| } | |
| nonsense('blah blah'); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var Module = function(){ | |
| var privateProperty = 'foo'; | |
| function privateMethod(args){ | |
| // do something | |
| }; | |
| return { | |
| publicProperty: "", | |
| publicMethod: function(args){ | |
| // do something | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var ifElse = function(condition, isTrue, isFalse){ | |
| if(condition){ | |
| isTrue(); | |
| } else { | |
| isFalse(); | |
| } | |
| }; | |
| var logTrue = function(){ console.log(true); }; | |
| var logFalse = function(){ console.log(false); }; |