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
| //1 | |
| function Car(make, model, year, owner) { | |
| this.make = make; | |
| this.model = model; | |
| this.year = year; | |
| this.owner = owner; | |
| //Notice the use of this to assign values to the object's properties based on the values passed to the function. | |
| } | |
| //2 |
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
| $("#name").keyup(updateName) | |
| function updateName() { | |
| var name=$("#name").val(); | |
| $("#user-name").text(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
| $("#big-button").click(showSomething) | |
| function showSomething() { | |
| alert ('You clicked me'); | |
| } |
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( myvar==1 || myvar==5 || myvar==7 || myvar==22 ) alert('yeah') | |
| //shorthand | |
| if([1,5,7,22].indexOf(myvar)!=-1) alert('yeah baby!') |
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 i=0; | |
| while (i<9) | |
| { | |
| //do stuff | |
| i++; //say | |
| } | |
| //shorthand | |
| var i=9; |
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
| switch (something) { | |
| case 1: | |
| doX(); | |
| break; | |
| case 2: | |
| doY(); | |
| break; | |
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
| "myString".charAt(0); | |
| //shorthand | |
| "myString"[0]; // Returns 'm' |
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 < allImgs.length; i++) | |
| //shorthand | |
| for(var i in allImgs) | |
| //with array | |
| function logArrayElements(element, index, array) { | |
| console.log("a[" + index + "] = " + element); | |
| } | |
| [2, 5, 9].forEach(logArrayElements); |
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 myFunction( myString, myNumber, myObject, myArray, myBoolean ) { | |
| // do something... | |
| } | |
| myFunction( "String", 1, [], {}, true ); | |
| //shorthand | |
| function myFunction() { | |
| console.log( arguments.length ); // Returns 5 | |
| for ( i = 0; i < arguments.length; 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
| if (likeJavaScript == true) | |
| //shorthand | |
| if (likeJavaScript) | |
| //another version | |
| var a; | |
| if ( a != true ) { | |
| // do something... | |
| } |