Object Property Shorthand

 Object Property Shorthand


Object property shorthand allows you to create objects more concisely by using variable names as property names.



const name = 'John';

const age = 30;


const person = { name, age };

console.log(person);

// Output: { name: 'John', age: 30 }

In the example above, object property shorthand is used to create the person object. Instead of explicitly specifying name: name and age: age, the shorthand syntax allows you to directly use the variable names as property names.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...