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 calculateTotal = function f(item) { | |
| var tax= 0.08; | |
| var fee = 10; | |
| var sinTax = 0.02; | |
| var h = { | |
| 'gas': function(price) { | |
| return price + price*tax + fee; | |
| }, | |
| 'wine': function(price) { | |
| return price + price*tax + price*sinTax; |
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 calculateTotal = function(item, price) { | |
| var tax= 0.08; | |
| var fee = 10; | |
| var sinTax = 0.02; | |
| switch (item) { | |
| case 'gas': | |
| return price + price*tax + fee; | |
| case 'wine': | |
| return price + price*tax + price*sinTax; |
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 myarr = ["a", "b", "c"]; | |
| function iterator(arr) { | |
| var idx = 0; | |
| return function () { | |
| return arr[idx++]; | |
| } | |
| } | |
| var getNext = iterator(myarr); |
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
| for (var i = 0; i < 100; ++i) { | |
| myElements[i].onclick = (function(n) { | |
| return function() { | |
| alert( 'You clicked on: ' + n ); | |
| }; | |
| })(i); | |
| } |
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 myElements = [ /* DOM Collection */ ]; | |
| for (var i = 0; i < 100; ++i) { | |
| myElements[i].onclick = function() { | |
| alert( 'You clicked on: ' + i ); | |
| }; | |
| } |
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 tax= 0.08; | |
| var fee = 10; | |
| var sinTax = 0.02; | |
| (function f(item, price) { | |
| var h = { | |
| 'gas': function() { | |
| var total = price + price*tax + fee; | |
| alert(total); | |
| }, |
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
| a = {}; | |
| function outer() { | |
| var b = 0; | |
| var c = function inner() { | |
| var d = 10; | |
| b = d + b + 1; | |
| console.log(b); | |
| } | |
| a = c; |
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
| a = {}; | |
| function outer() { | |
| var b = 0; | |
| var c = function inner() { | |
| var d = 10; | |
| b = d + b + 1; | |
| console.log(b); | |
| } | |
| a = c; |
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
| <script> | |
| var globalVar = "Hello"; | |
| var foo = function(param) { | |
| var foo = 'bar'; | |
| alert(globalVar + " " + param); | |
| console.log(foo); | |
| }; | |
| foo("World"); | |
| </script> | |
| <div>Hello World</div> |
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
| <script> | |
| var globalVar = "Hello"; | |
| (function() { | |
| var localVar = "World"; | |
| alert(globalVar + " " + localVar); | |
| })(); | |
| </script> | |
| <div>Hello World</div> |