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 expression | |
| function | |
| optional name | |
| parameters | |
| wrapped in () | |
| zero or more names | |
| separated by a comma | |
| body | |
| wrapped in {} | |
| zero or more statements |
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
| hoisting in functions concern variables | |
| The var statement gets spit into two parts: | |
| The declaration part gets hoisted to the top of the function, initializing with undefined. | |
| The initialization part turns into an ordinary assignment. | |
| var myVar = 0, myOtherVar; | |
| Expands into | |
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
| JavaScript is a protypal language but has syntax that is more similar to a classical language which can be confusing. | |
| Function as module (using self-executing function ) is a way to do functions better in some instances. | |
| Function as module safeguards against values being exposed b/c it limits scope: | |
| (function () { | |
| var ... | |
| function ... | |
| function ... | |
| }()); |
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 people = ['Jim', 'Bob', 'Jane', 'Jill']; | |
| var welcomes = people.map(function(name) { | |
| return 'Hi' + ' ' + name + '!'; | |
| }); |
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
| // arr.forEach(callback[, thisArg]) | |
| // REMEMBER!! The forEach uses a function | |
| // The forEach() method executes a provided function once per array element. | |
| // The function can be written outside of the forEach() and called in the forEach() or | |
| // the function can be written inside of the forEach. | |
| // You cannot break from a forEach(). | |
| // Each of the 3 code blocks below uses the same function written inside of the forEach(). | |
| // also these functions were between script tags in the .html file, if in ext file, they would need to be slightly modified using the this keyword | |
| // For performance-critical scenarios (“hot paths,” tight loops, etc.), a classic for loop is better because the Javascript interpreter can better optimize it. This is also necessary if you need to break from the loop, which you cannot do with forEach. | |
| // http://www.kraigbrockschmidt.com/2013/01/22/array-enumeration-javascript/ |
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
| .. |
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
| from: http://stackoverflow.com/questions/9329446/how-to-do-for-each-over-an-array-in-javascript | |
| For Actual Arrays | |
| (See "For Array-Like Objects" below for array-like objects.) | |
| You currently have three options and will soon have two more: | |
| Use forEach and related (ES5+) | |
| Use a simple for loop |
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(in) loops through the enumerable properties of an object, not the indexes of an array | |
| console.log('The primary use case for for(in) is to enumerate the properties of an object and will result in unexpected results if used with an Array'); | |
| console.log('for(in) gives you the index positions of the items if used in the array and not an objecct:'); | |
| console.log('the results below are from using a for(in) with var myNewArray = ["a", "b", "c", "d"]'); | |
| var myNewArray = ["a", "b", "c", "d"]; | |
| for (var i in myNewArray) { | |
| console.log('i', 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
| The input element with a type attribute whose value is "file" represents a list of file items, each consisting of a file name, a file type, and a file body (the contents of the file). | |
| http://www.w3.org/TR/html-markup/input.file.html | |
| http://msdn.microsoft.com/en-us/library/windows/apps/hh466145.aspx | |
| Read Text Files Using the JavaScript FileReader | |
| http://www.htmlgoodies.com/beyond/javascript/read-text-files-using-the-javascript-filereader.html | |
| READONLY information for an individual file such as its name, size, mimetype, and a reference to the file handle. Adding the "multiple" attribute to the file input element (as in <input type="file" multiple/> will get you a list of files | |
| <input type="file"/> | |
| input always returns a FileList object |
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 range(max) { | |
| var retVal = []; | |
| for (var i = 0; i < max; i++) { | |
| retVal.push(i * 2); | |
| } | |
| return retVal; | |
| } | |
| var myArray = range(5); |