JavaScript Objects

Object shorthand

In some circumstances, we can use the ES6 object shorthand syntax to avoid having to define object keys. Take this example for instance:

let person = {
	name: name,
	email: email,
	phone: phone
};

Where name, email and phone are all variables. In this case we can emit the key definitions and Javascript will use the variable name as the key name. So the above can be defined as the following:

let person = {
	name,
	email,
	phone
};

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *