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
| 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
| //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
| //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
| 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
| 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
| function AnimalMaker(name) { | |
| return { | |
| speak: function () { | |
| console.log("my name is ", name); | |
| }, | |
| name: name, | |
| owner: "jason" | |
| }; | |
| }; |
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
| // We are creating a constructor | |
| function AnimalMaker(name) { | |
| return { | |
| speak: function () { | |
| console.log("my name is ", name); | |
| }, | |
| name: name, | |
| owner: "jason" | |
| }; | |
| }; |
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['size'] = true; | |
| box[3] = {'hey': true}; | |
| console.log(box.length); |
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['size'] = 9; // doesn't return size because it's a string and not integer | |
| box['0'] = 'meow'; | |
| box.push("Whoohoo"); | |
| for(var i =0; i < 2; i++) { | |
| console.log(box[i]); | |
| } |