Computed property names

Property names that are evaluated during runtime are called computed property names. An expression is usually resolved to find the property name dynamically.
Computed properties were once defined in this way:

var object = {};
object["first"+"Name"] = "Eden";//"firstName" is the property name
//extract
console.log(object["first"+"Name"]); //Output "Eden"

Here, after creating the object, we attach the properties to the object. But in ES6, we can add the properties with the computed name while creating the object. The following example demonstrates this:

let object = {
["first" + "Name"]: "Eden",
};
//extract
console.log(object["first" + "Name"]); //Output "Eden"
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.186.158