JavaScript destructure directly into return statement

July 9, 2019

You can destructure an object directly into a return statement. No need to assign to a const first. Never tried this before and just assumed it does not work. 😅

const obj = { hello: 'world' }; function greet() { return ({ hello } = obj); } // logs {hello: 'world'} console.log(greet());