DEV Community

Manav Misra
Manav Misra

Posted on β€’ Edited on

1

Object Shorthand

'Collecting' an Object Pre-ES2015/ES6

Give Given some existing 'in scope' variables, if we wanted to 'collect' them into an object, before ES2015, we had to do:

const fname= "Mark";
const lname = "Galloway";
const aliases = ["Mean Mark", "The Undertaker", "American Bad Ass"];
const status = "retired";

const wrestler = {
  fname: fname,
  lname: lname,
  aliases: aliases,
  status: status
}
Enter fullscreen mode Exit fullscreen mode

'Collecting' An Object ES6+

Object Shorthand

const fname= "Mark";
const lname = "Galloway";
const aliases = ["Mean Mark", "The Undertaker", "American Bad Ass"];
const status = "retired";

/**
  * If there is no ':',
  * the OBJECT LITERAL automatically 'creates' a STRING πŸ”‘
  * and assigns the VALUE BOUND TO the VARIABLE IN SCOPE
  * that has the same name. πŸ¦„
  */
const wrestler = {
  fname,
  lname,
  aliases,
  status
}
Enter fullscreen mode Exit fullscreen mode

Summarily, this is a nice way to save some typing. Less typing ➑️ fewer mistakes and πŸ›s.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay