In addition, the recipient doesn’t have to work with the content in any specific way. This is a kind of object that lacks any sort of constructor and has no need for methods. The entire purpose of this technique is to make transferring data simpler and less error prone. Check out a real world example of how object literals are used.
Object literals rely on name and value pairs to store information. You provide a name (also called a label) and a data value to go with it. The recipient can then retrieve the data by name. The following example shows a simple use of an object literal.
In this case, customerData contains three values: Name, Age, and Birthday. Each of these labels has an associated value. Notice that you needn’t worry about mixing data type — the object literal doesn’t care. The important elements are to enclose the data within curly brackets, to provide a name for each value, to separate the value from the name by a colon, and to separate values with commas.
At this point, customerData is a package that you could send anywhere. The example uses the information directly after the object literal is created. Notice that you use standard dot syntax to access each of the values. The order of access doesn’t matter because you access the values by name.
For example, if you wanted to add a property named HairColor to the customerData example and give the customer a hair color of brown, you’d simply type customerData.HairColor = Brown;. The new property would appear as part of customerData as if you had provided it as part of the original object literal.