let type = 'quartz';
let color = 'rose';
let carat = 21.29;
const gemstone = {
type: type,
color: color,
carat: carat
};
Object {type: "quartz", color: "rose", carat: 21.29}
Another way is
const gemstone = { type, color, carat}
Also it could include a function
const gemstone = {
type, color, carat,
calculateWorth: function() {
// will calculate worth of gemstone based on type, color, and carat
}
};
Even shorter…
let gemstone = {
type,
color,
carat,
calculateWorth() { ... }
};
Source: https://www.udacity.com/course/es6-javascript-improved–ud356