// Rest operator
function bestPokemons(first, second, ...others) {
return {
first, second, others
}
}
JSON.stringify(bestPokemons('pikachu', 'bulbizarre', 'pokemon1', 'pokemon2'))
// {"first":"pikachu","second":"bulbizarre","others":["pokemon1","pokemon2"]}
// Spread (array and object)
// Copy an array
const pokemons = ['pikachu', 'bulbizarre']
const pokemonsCopy = [...pokemons]
JSON.stringify(pokemonsCopy)
// ["pikachu","bulbizarre"]
// Copy an object
const pokemon = {name: 'pikachu', attack: 100, defense: 50}
const clonedPokemon = {...pokemon, name: 'cloned pikachu'}
JSON.stringify(clonedPokemon)
// {"name":"cloned pikachu","attack":100,"defense":50}