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 myFunc; | |
| var num = 0; | |
| if (num === 0){ | |
| myFunc = function(theObject) { | |
| theObject.make = "Toyota"; | |
| theObject.year = "2003"; | |
| return theObject; | |
| }; | |
| } |
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 square = function(number) {return number * number}; | |
| var x = square(4) //x gets the value 16 |
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
| //put this in the console | |
| monitorEvents(window) | |
| //only mouse events | |
| monitorEvents(window, 'mouse') | |
| //only keyboard events | |
| monitorEvents(window, 'key') | |
| //only scroll activity |
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
| $('body').on({ | |
| click: function() { | |
| event.preventDefault(); | |
| console.log('item anchor clicked'); | |
| }, | |
| mouseenter: function() { | |
| console.log('enter!'); | |
| } | |
| }); |
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
| // Arrays | |
| var trees = new Array("redwood", "bay", "cedar", "oak", "maple"); | |
| 0 in trees; // returns true | |
| 3 in trees; // returns true | |
| 6 in trees; // returns false | |
| "bay" in trees; // returns false (you must specify the index number, | |
| // not the value at that index) | |
| "length" in trees; // returns true (length is an Array property) | |
| // Predefined objects |
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 delete operator deletes an object, an object's property, or an element at a specified index in an array. Syntax: | |
| delete objectName; | |
| delete objectName.property; | |
| delete objectName[index]; | |
| delete property; // legal only within a with statement | |
| //If the delete operator succeeds, it sets the property or element to undefined. | |
| //The delete operator returns true if the operation is possible; it returns false if the operation is not possible. | |
| x = 42; |
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 age = 19; | |
| if(age >= 18){ | |
| var status = "adult"; | |
| }else{ | |
| var status = "minor"; | |
| } | |
| //short hand version | |
| var status = (age >= 18) ? "adult" : "minor"; |
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 myHonda = {color: "red", wheels: 4, engine: {cylinders: 4, size: 2.2}}; | |
| //console edits and results | |
| myHonda.color | |
| "red" | |
| myHonda.engine | |
| Object {cylinders: 4, size: 2.2} | |
| myHonda.engine.size | |
| 2.2 | |
| myHonda.engine.size = "3.3" |
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
| if (cond) var x = {hi: "there"}; |
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
| //create the object with properties & values. | |
| var myCar = new Object(); | |
| myCar.make = "Ford"; | |
| myCar.model = "Mustang"; | |
| myCar.year = 1969; | |
| //then LOOP(enumerate) through all the properties of the object myCar | |
| function showProps(obj, objName) { | |
| var result = ""; | |
| for (var i in obj) { |