In this example, person is an object that has four properties: firstName, lastName, age, and fullName. The fullName property is a method that returns the full name of the person. Remember that objects can also contain methods as you see in the above example.
- Constructor function:
In this example, Person is a constructor function that creates an object with the same properties and methods as the object created using object literal notation.
In dot notation first you specify the name of the object and then the name of the property. If that property does not exist it will return undefined since that property is not defined in the object.
In bracket notation you specify name of your object, open a bracket then type name of your property and finally close the bracket.
To delete a property using dot notation, you simply write the object name followed by a dot and the property name, and then apply the delete keyword:
To delete a property using bracket notation, you enclose the property name in square brackets after the object name, and then apply the delete keyword: