DEV Community

Star
Star

Posted on

2

Write Concise Object Literal Declarations Using Object Property Shorthand

Write Concise Object Literal Declarations Using Object Property Shorthand

ES6 has yet another special feature for defining object literals, ergo, the data propogated into the object can be defined and sorted with built-in shortcuts.

The old way to define x as x and y as y:

const getMousePosition = (x, y) => ({
  x: x,
  y: y
});
Enter fullscreen mode Exit fullscreen mode

The β€œnew” 😎 way

const getMousePosition = (x, y) => ({ x, y });
Enter fullscreen mode Exit fullscreen mode

Prompt

Use object property shorthand with object literals to create and return an object with name, age and gender properties.

const createPerson = (name, age, gender) => {
  // Only change code below this line
  return {
    name: name,
    age: age,
    gender: gender
  };
  // Only change code above this line
};
Enter fullscreen mode Exit fullscreen mode

Solution

const createPerson = (name, age, gender) => {
  // Only change code below this line
  return  {name, age, gender
  };
  // Only change code above this line
};
Enter fullscreen mode Exit fullscreen mode

Unfortunately, I cannot see any new understanding in this as I don’t have the experienced perspective of the old way, just that from the example. Makes this post kinda feel like bloat but how else would I remember it?

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (1)

Collapse
 
muhammadmehedihasanopisarker profile image
Muhammad Mehedi Hasan β€’

good explanation.

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free β†’

πŸ‘‹ Kindness is contagious

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

Okay