Lesson 20 of 55 · javascript
Object Literals, Shorthand & Destructuring
Duration: 10 mins
Object literal shorthand:
const name = 'John';
const user = { name, age:30, greet(){ console.log('hi'); } };
Destructuring makes extracting values easy:
const {name, age} = user;
const [first, second] = [10,20];
Nested destructuring:
const {address:{city}} = user;
Example: Function parameter destructuring
function render({title, content, author='Anonymous'} = {}){
console.log(title, content, author);
}
render({title:'Demo', content:'Hello'});