An example of an object would be a cake. A cake has different properties such as flavor and size. All cakes have these properties however, each cakes properties differ. Some cakes could be vanilla flavored with 3 layers, or chocolate flavored with 2 layers.
Accessing Object Properties
To access our object properties we can access them in two different ways:
Using our previous cake example, this would look like the following:
Methods are actions that can be performed on objects and they are stored in properties as function definitions.
Accessing Object Methods
There are different ways you can access an object method:
- let name = person.fullName()
Using our cake example this would look like the following:
If you don’t put the () after the method, then it will return the function definition. The () calls the function.