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
| //Properties defined in constructor | |
| function Person(first, last, age, gender, interests) { | |
| this.name = { | |
| first, | |
| last | |
| }; | |
| this.age = age; | |
| this.gender = gender; | |
| this.interests = interests; | |
| }; |
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 person = { | |
| name : { | |
| first: 'Bob', | |
| last: 'Smith' | |
| }, | |
| age: 32, | |
| gender: 'male', | |
| interests: ['music', 'skiing'], | |
| greeting: function() { | |
| alert('Hi! I\'m ' + this.name.first + '.'); |
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 myButton = document.querySelector('button'); | |
| myButton.onclick = function() { | |
| alert('hello'); | |
| } |
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 (expression) { | |
| case choice1: | |
| run this code | |
| break; | |
| case choice2: | |
| run this code instead | |
| break; | |
| // include as many cases as you like |
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 mixedArray = ['foo', [3, 1, 7, 15], 23]; | |
| var num = mixedArray[1][2]; //7 | |
| mixedArray.push(213); //['foo', [3, 1, 7, 15], 23, 213] | |
| mixedArray.pop(); //['foo', [3, 1, 7, 15], 23] | |
| mixedArray.unshift(456); //[456, 'foo', [3, 1, 7, 15], 23] | |
| mixedArray.shift(); //['foo', [3, 1, 7, 15], 23] |
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 myString = "MyString"; | |
| var len = myString.length; //8 | |
| var mine = myString.indexOf('My'); //0 | |
| var yours = myString.indexOf('Your'); //-1 | |
| var string = myString.slice(2); //String | |
| var str = myString.slice(2,5); //Str | |
| myString.replace('My', 'Your'); | |
| var towns = 'Manchester,London,Liverpool,Birmingham,Leeds,Carlisle'; | |
| var townsArray = towns.split(','); | |
| var townsCopy = townsArray.join(','); |
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 myDate = '19' + '67'; | |
| typeof myDate; //Number | |
| var myString = '123'; | |
| var myNum = Number(myString); | |
| typeof myNum; //Number | |
| var myNum = 123; | |
| var myString = myNum.toString(); | |
| typeof myString; //String |
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
| submitButton.disabled = true; | |
| textEntryField.focus(); |
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
| element.style.backgroundColor = 'white'; |
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 createParagraph() { | |
| var para = document.createElement('p'); | |
| para.textContent = 'You clicked the button!'; | |
| document.body.appendChild(para); | |
| document.body.removeChild(para); | |
| } |
NewerOlder