7 Hacks for ES6 Developers

Last updated 1 year ago by Tal Bereznitskey

ES6

Hack #1 — Swap variables

Using Array Destructuring to swap values

let a = 'world', b = 'hello' [a, b] = [b, a] console.log(a) // -> hello console.log(b) // -> world // Yes, it's magic

Hack #2 — Async/Await with Destructuring

Once again, Array Destructuring is great. Combined with async/await and promises to make a complex flow — simple.

const [user, account] = await Promise.all([ fetch('/user'), fetch('/account') ])

Hack #3 — Debugging

For anyone who likes to debug using console.logs, here’s something awesome (and yes, I heard of console.table):

const a = 5, b = 6, c = 7 console.log({ a, b, c }) // outputs this nice object: // { // a: 5, // b: 6, // c: 7 // }

Read full Article