Skip to content

Instantly share code, notes, and snippets.

@vladilenm
Created February 21, 2020 09:18
Show Gist options
  • Save vladilenm/3b6df3316301236c3334b5b9fb34a888 to your computer and use it in GitHub Desktop.
Save vladilenm/3b6df3316301236c3334b5b9fb34a888 to your computer and use it in GitHub Desktop.
function calcValues(a, b) {
return [
a + b,
a - b,
a * b,
a / b
]
}
const [sum, sub = 'Вычитания нет', mult, ...other] = calcValues(42, 10)
// const sum = result[0]
// const sub = result[1]
// const [sum, sub] = result
console.log(sum, mult, other, sub)
// Objects
const person = {
name: 'Max',
age: 20,
address: {
country: 'Russia',
city: 'Moscow'
}
}
// const name = person.name
const {
name: firstName = 'Без имени',
age,
car = 'Машины нет',
address: {city: homeTown, country}
} = person
// const {name, ...info} = person
// console.log(name, info)
function logPerson({name: firstName = '111', age}) {
console.log(firstName + ' ' + age)
}
logPerson(person)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment