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
typeof Bunny | |
// 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
class Bunny { | |
constructor(name, age, favoriteFood){ | |
this.name = name; | |
this.age = age; | |
this.favoriteFood = favoriteFood; | |
} | |
eatFavFood() { | |
console.log(`"Mmmm! Those ${this.favoriteFood} were delicious", said ${this.name} the ${this.age} year old bunny.`); | |
}; |
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 Bunny(name, age, favoriteFood) { | |
this.name = name; | |
this.age = age; | |
this.favoriteFood = favoriteFood; | |
} | |
Bunny.prototype.eatFavFood = function () { | |
console.log('\"Mmmm! Those ' + this.favoriteFood + ' were delicious\", said ' + this.name + ', the ' + this.age + ' year old bunny.'); | |
}; |
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 general syntax: str.repeat(count); | |
// Examples: | |
'Bunny'.repeat(3); // => BunnyBunnyBunny | |
'Bunny'.repeat(2.5)// => BunnyBunny | |
'Bunny'.repeat(10/2) // => BunnyBunnyBunnyBunnyBunny | |
'Bunny'.repeat(-3) // => RangeError: Invalid count value | |
'Bunny'.repeat(1/0) // => RangeError: Invalid count value |
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 aboutEdward = { | |
info: ['Edward', 30], | |
favColor: 'blue', | |
favSushiRoll: 'Squidy squid squid' | |
} | |
function profilePage({favColor} = {favColor: 'vintage pink'}, [name, age] = ['Bunny', 24]) { | |
console.log(`My name is ${name}. I am ${age} years old and my favorite color is ${favColor}!`) | |
} | |
profilePage(); |
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 profilePage({favColor: favColor} = {favColor: 'vintage pink'}, [name, age] = ['Bunny', 24]) { | |
console.log(`My name is ${name}. I am ${age} years old and my favorite color is ${favColor}!`) | |
} | |
profilePage(); | |
// => My name is Bunny. I am 24 years old and my favorite color is vintage pink! | |
profilePage({favColor: 'blue'}, ['Ed', 30]) | |
// => My name is Ed. I am 30 years old and my favorite color is blue! |
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 iceCream = { | |
cost: 3.99, | |
name: 'Ice Cream Flavors', | |
type: ['chocolate', 'vanilla', 'caramel', 'strawberry', 'watermelon'] | |
} | |
var sushi = { | |
cost: 5.99, | |
name: 'Sushi Combinations', | |
type: ['Eel Roll', 'Philadelphia Roll', 'Spicy Salmon Handroll', 'Rainbow Roll', 'Special Roll'] |
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 {cost, title, type} = { | |
cost: 3.99, | |
title: 'Ice Cream Flavors', | |
type: ['chocolate', 'vanilla', 'caramel', 'strawberry', 'watermelon'] | |
} | |
// VOILA! | |
console.log(cost, title, type[2]) | |
//=> 3.99 'Ice Cream Flavors' 'caramel' |
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 iceCream = { | |
cost: 3.99, | |
title: 'Ice Cream Flavors', | |
type: ['chocolate', 'vanilla', 'caramel', 'strawberry', 'watermelon'] | |
} | |
console.log(iceCream.cost, iceCream.title, iceCream.type[2]); | |
//=> 3.99 ‘Ice Cream Flavors’ ‘caramel’ |
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
// Every additional comma added will represent the next item in the array. | |
var [firstItem,,,,fifthItem] = ['Carrots', 'Carrot Bits', 'Grass', 'Berries', 'Papaya', 'Apples']; | |
console.log(firstItem) // => Carrots | |
console.log(fifthItem) // => Papaya | |
// Wohoo! Let’s try some more! Which item in the array will this get? | |
var [firstItem,,guessThisItem,,fifthItem] = ['Carrots', 'Carrot Bits', 'Grass', 'Berries', 'Papaya', 'Apples']; | |
console.log(firstItem) // => Carrots | |
console.log(guessThisItem) // => Grass | |
console.log(fifthItem) // => Papaya |