February 2018
Intermediate to advanced
298 pages
8h 22m
English
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//extractconsole.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",};//extractconsole.log(object["first" + "Name"]); //Output "Eden"
Read now
Unlock full access