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, and they are used to simulate the behaviors of real-world objects. Methods are properties of an object and operate on that object's data.

Question 2

Why would we want to add methods to an object?

An object is made up of properties, which mainly describe the object. But when adding a method, it allows the code to also describe the behavior of the object.

Question 3

How can we access the property of an object from inside the body of a method of that object?

When accessing the property of the object, you would need to use this. at the beginning of the property.
For example: this.name

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.