concat() method on Mozilla, we'll actually discover that there are two different
While we are already familiar with strings, we haven't learned about arrays yet. Don't worry! We'll begin learning about arrays in the next lesson.
According to the Mozilla documentation:
When we refer to
String.prototype.concat(), we are referring to a
concat() method that all strings inherit. When we say
Array.prototype.concat(), we are referring to a
concat() method that all arrays inherit. Even though these methods have the same name, they are actually different methods. Sure, they do essentially the same thing: they put things together. When called on strings, they put two strings together. When called on arrays, they add something to the end of the array.
How do arrays or strings know how to
So let's reiterate what we do need to know. We'll often see
prototype in the following context when we are looking at documentation:
Array.prototype.join(). In this case,
prototype refers to a method that can be called on a type of object. This is relevant because we are about to add a different kind of object to our toolbox - arrays - and we need to be clear that arrays have a different set of methods than strings and other objects, even though these methods sometimes have the same names.
Array.prototype.concat(). We want to make sure you're not confused when we start doing this. It's just a way to make things clearer. By the way, any time you see the
prototype keyword like this, we know that we are using a method, not just a function. That's because prototypal inheritance uses objects - and any time a function needs to be called on a type of object, it is a method.
And if you really have to look into prototypal inheritance more to get a grasp on all of this, see the Mozilla documentation on Object prototypes. This is an advanced topic - and at this point, we recommend steering clear of it. Many experienced developers find it confusing, too.
Lesson 2 of 34
Last updated October 12, 2021