Skip to content

Instantly share code, notes, and snippets.

typeof Bunny
// function
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.`);
};
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.');
};
// 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
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();
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!
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']
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'
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’
// 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