JavaScript Methods Worksheet
Question 1
How is a method different from a regular function in JavaScript?
A method is a function that is defined inside of an object, they are used to simulate
behaviors of real-world objects. So once the behaviors of an object are defined the function becomes
a 'method'.
Question 2
Why would we want to add methods to an object?
There are many benefits to adding methods to objects, the most important one to consider is that
methods allows us to model objects in ways that mimic real-world items and in adding methods our objects have
both data and actions working together.
Question 3
How can we access the property of an object from inside the body of a method of that object?
To access the property of an object from inside a method we want to use the this keyword followed
by the dot operator so the end result becomes this.('name of property').
Coding Problems
Coding Problems - See the 'script' tag below this h3 tag. You will have to write some JavaScript code in it.
Always test your work! Check the console log to make sure there are no errors.