Created
March 26, 2019 02:50
-
-
Save micahriggan/51fd9db1cc9b09fd8041072da8cf87ef to your computer and use it in GitHub Desktop.
Common examples of destructuring objects
This file contains 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 Book = { | |
title: 'A book title', | |
pages: 55, | |
height: 100, | |
weight: 2, | |
price: 3.50 | |
}; | |
function test1() { | |
const {title} = Book; | |
console.log(title); | |
} | |
function test2() { | |
const {title, pages} = Book; | |
console.log({title, pages}); | |
} | |
function test3() { | |
const {height: bookHeight} = Book; | |
console.log(bookHeight); | |
} | |
function test4() { | |
const {ISBN = '0000000'} = Book; | |
console.log(ISBN); | |
} | |
function test5() { | |
const {title, ...rest} = Book; | |
console.log(rest); | |
} | |
test1(); | |
test2(); | |
test3(); | |
test4(); | |
test5(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment