JavaScript Methods Worksheet

Question 1

How is a method different from a regular function in JavaScript?

Methods are different because a method is always associated with an object, and is usually used to execute actions related to that object, while regular functions can exist independently.

Question 2

Why would we want to add methods to an object?

To encapsulate functionality that's specific to the object.

Question 3

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

Inside a method, the this keyword is used to refer to the current object, which allows you to access the objects properties from inside the method.

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.