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
const pokemon = { | |
id: 1, | |
name: 'Squirtle', | |
type: 'Water' | |
}; | |
const { id, ...rest } = pokemon; | |
console.log(rest); //Result: { name: 'Squirtle', type: 'Water' } |
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
const pokemon = { | |
name: 'Squirtle', | |
type: 'Water', | |
abilities: ['Torrent', 'Rain Dish'] | |
}; | |
const { abilities = [], ...rest } = pokemon; | |
const fullSquirtle = { ...rest, abilities }; | |
console.log(rest); //Result: { name: 'Squirtle', type: 'Water' } |
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
const pokemon = { | |
id: 1, | |
name: 'Squirtle' | |
}; | |
const { type, name } = pokemon; | |
console.log(name); //Result: Squirtle | |
console.log(type); //Result: undefined | |
//Assigning default value to the type variable |
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
const pokemon = [ | |
{ | |
name: 'Charmander', | |
type: 'Fire' | |
}, | |
{ name: 'Squirtle', type: 'Water', abilities: ['Torrent', 'Rain Dish'] }, | |
{ | |
name: 'Bulbasur', | |
type: 'Plant' | |
} |
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
const pokemon = { | |
useless: 'useless property', | |
id: 1, | |
name: 'Squirtle', | |
type: 'Water' | |
}; | |
// Removing the useless property: | |
({ useless, ...newPokemon } = pokemon); | |
console.log(newPokemon); // Result: { id: 1, name: 'Squirtle', type: 'Water' } |
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
const pokemon = { | |
useless: 'Useless property', | |
id: 1, | |
name: 'Squirtle', | |
useless2: 'Another useless prop', | |
type: 'Water' | |
}; | |
// Removing both useless and useless2 properties: | |
({ id, useless, useless2, ...newPokemon } = pokemon); |
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
const pokemon = { | |
useless: 'useless property', | |
id: 1, | |
name: 'Squirtle', | |
type: 'Water' | |
}; | |
function removeProperty(property, object) { | |
({ [property]: value, ...newObject } = object); | |
return newObject; |
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
const pokemon = { | |
useless: 'useless property', | |
id: 1, | |
name: 'Squirtle', | |
type: 'Water' | |
}; | |
const remove = (property, { [property]: value, ...newObject }) => newObject; | |
console.log(remove('useless', pokemon)); // Result: { id: 1, name: 'Squirtle', type: 'Water' } |
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 publishTweet(tweet) { | |
if (isLoggedIn()) { | |
if (tweet) { | |
if (isTweetDoubleChecked()) { | |
tweetIt(tweet); | |
} else { | |
throw new Error('Dont publish without double checking your tweet'); | |
} | |
} else { | |
throw new Error("Your tweet is empty, can't publish it"); |
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 publishTweet(tweet) { | |
if (!isLoggedIn()) { | |
throw new Error('You need to log in before tweeting'); | |
} | |
if (!tweet) { | |
throw new Error("Your tweet is empty, can't publish it"); | |
} | |
if (!isTweetDoubleChecked()) { | |
throw new Error('Dont publish without double checking your tweet'); |