JavaScript Methods Worksheet

Question 1

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

A method is a function that is stored inside of an object. In our example our object is dog and the method the dog uses is bark. bark would be the function stored in the object. To call the function it would be: dog.bark

Question 2

Why would we want to add methods to an object?

The methods are tied to the object in some way. For instance lets say send was a method of email. It doesnt really make sense outside of that function; however, within email it makes sense.

Question 3

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

this.propertyName

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.