What does prototype in the documentation mean?

I have a question about the docs.
When searching for something like methods available for strings, the documentation shows:

String.prototype

and then in the method area something like:

String.prototype.charAt(index)
– Returns the character (exactly one UTF-16 code unit) at the specified index .

It throws me off because I am not sure where the word prototype comes into the mix. What does that mean? Why not just String Methods? or String.method?

I suppose this has always been my issue when looking at docs is that I get there, and there is extra stuff I don’t understand. More than what is being explained in tutorials.

Objects all have a constructor, or class, which has its own methods, but also methods that it affords to all members, or instances.

Objects do not inherit from Object. To call its methods we must use the Object context. Every constructor/class has a prototype that defines the inherited attributes for each instance. In most cases, these attributes are methods.

JavaScript looks for methods on the prototype chain. Every object has a prototype chain by which to access methods. Everything traces back to the parent object, Object. It is the last objective link in the chain. After that there is only null.

The top of the prototype chain is, null. After that it is Object.prototype. After that we begin to split off new special or custom objects which each have their own prototype.

We inherit the charAt() method from String.prototype. We are however carrying out that method on the string object itself. Since its object type has inherited the method from String.prototype we already have an instance of the method without referring to it along the prototype chain. We can access it directly on the instance (context).

"Abracadabra".charAt(6)    //  d
1 Like

Hello, what is up with the Mozilla Documentation because when I looked up for “trim()” is states that one should do “String.prototype.trim()”, what is “prototype”?

javascript uses propotype for objects, where many other languages use inheritance.

I don’t think you should worry to much about it at the moment, something for later

1 Like

Ok, as the tutorial said to me to look it up by myself I went and did that but I got lost when I couldn’t find a working solution.
Thanks

Looking up .trim() is fine, but prototype is something i would leave for later

Yes, if you look for “trim()” here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String (that’s where the tutorial points to) you’ll see that out of nowhere it comes up with “prototype”, that’s where I got the confusion.
Thanks, I just used trim() in the end to move forward.