Open In App
Related Articles

Shorthand Syntax for Object Property Value in ES6

Improve Article
Improve
Save Article
Save
Like Article
Like

Objects in JavaScript are the most important data-type and forms the building blocks for modern JavaScript. These objects are quite different from JavaScript primitive data-types (Number, String, Boolean, null, undefined, and symbol) in the sense that while these primitive data-types all store a single value each (depending on their types).

The shorthand syntax for object property value is very popular and widely used nowadays. The code looks cleaner and easy to read. The shorthand property makes the code size smaller and simpler.

Example: This example displaying the details of object using shorthand Syntax for object property value in ES6.




// Object property shorthand
const name = 'Raj'
const age = 20
const location = 'India'
  
// User with ES6 shorthand
// property 
const user = {
    name,      
    age,
    location
}
  
console.log(user) 


Output:
Output of above command

Example: This example displaying the details of the object without using shorthand Syntax for object property value.




// Object property shorthand
const name = 'Raj'
const age = 20
const location = 'India'
  
// User without ES6 
// shorthand property 
const user = {
    name: name,      
    age: age,
    location: location
}
  
console.log(user) 


Output:
Output of above command

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 20 May, 2020
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials