Programming Popular

Use Object Shorthand Properties

Creating objects from variables requires repetitive key-value pairs. Use ES6 shorthand to omit the value when key and variable name are the same.

Problem

Creating objects from variables requires repetitive key-value pairs.

Solution

Use ES6 shorthand to omit the value when key and variable name are the same.

Benefit

Reduces object creation code by 50% and improves readability.

Code Example

const name = 'John';
const age = 30;
const city = 'NYC';

// Instead of:
const user1 = {name: name, age: age, city: city};

// Use:
const user2 = {name, age, city};

ES
Edrees Salih
7 hours ago

We are still cooking the magic in the way!