Today I Learned

hashrocket A Hashrocket project

Object so nice I destructured it twice!

I learned today that you can destructure javascript object keys multiple times:

const obj = {a: 1};

const {a: c, a: d} = obj;

c === d
// evaluates to true

This is nice when you want to destructure specific keys for convenience but still need to operate on the whole object, like this:

const {bigObj, bigObj: {isError}} = deepObj;
See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.