DEV Community

Cover image for What is the Difference Between a Function and a Method in JavaScript?
tiff
tiff

Posted on

Method vs Function What is the Difference Between a Function and a Method in JavaScript?

This article was originally posted on my blog.

Abby Snopek tweeted the following:

In short: a method is a function that belongs to a class. In JavaScript, however, a method is a function that belongs to an object.

Everything in JavaScript is an object; a function is an object; an Array is an object. This is a quirky design decision, but because most everything in JavaScript is an object, we can do neat things with Prototypal Inheritance. The nice thing about prototypal inheritance is that we can manipulate several different properties on the prototype chain at once.

Give that above article a read for more information. Also, check out the Inheritance and the prototype chain article on MDN.

Update: I wrote this post without coffee and realized I should show some examples. Will rectify this after my java ☕.


Sign Up for the Newsletter. No spam. I hate that, too.

https://buttondown.email/tiffanywhite

Oldest comments (4)

Collapse
 
phoinixi profile image
Francesco Esposito • Edited

Thanks for this article!

Another way to say it, it’s that a method is a function with a defined this

Collapse
 
tiffany profile image
tiff

Thanks for the tip.

Collapse
 
radoncreep profile image
radoncreep

Thanks for this

Collapse
 
k8hansen profile image
Kate Hansen

Perfect! Very clear and awesome, thanks!