r/learnjavascript • • Mar 18 '18

Easier way to create objects with dynamic keys 💪

Post image
0 Upvotes

6 comments sorted by

12

u/CertainPerformance Mar 18 '18

ES6 way: don't use var

1

u/GoDayme Mar 18 '18

let would be correct?

4

u/CertainPerformance Mar 18 '18

No, const, because it doesn't get reassigned. const is much easier to reason about.

-2

u/samanthaming Mar 18 '18

Agreed! I didn’t want to mix es6 with the old way example and confuse people. const and let all the way 😀👍

-4

u/samanthaming Mar 18 '18

Easier way to create objects with dynamic keys 💪

Previously, we always had to use the bracket notation to use a dynamic key. With ES6, we can finally create dynamic variable key in the object declaration. Woohoo! 🤩

0

u/[deleted] Mar 18 '18

[deleted]

-3

u/samanthaming Mar 18 '18

I didn’t want to mix es6 concepts with the old example and possibly confuse people. Var should definitely be avoided, instead you should use const or let 🙂