The difference between a static method and an instance method

Photo by Andrew Neel on Unsplash

The difference between a static method and an instance method

Static methods belong to a class and don't act on instances, while instance methods belong to the class prototype, which is inherited by all instances of the class and acts on them.

Code Sample:

Array.isArray // static method of Array
Array.prototype.push // instance method of Array

In this case, the Array.isArray method does not make sense as an instance method of arrays because we already know the value is an array when working with it.

Instance methods could technically work as static methods, but provide terser syntax:

Code Sample:

const arr = [1, 2, 3]
arr.push(4)
Array.push(arr, 4)

Thanks for reading...

Happy Coding!