What is prototype?

What is actually a Prototype used several times in MDN, what does it mean?
string.prototype.tolowercase()
object.prototype

And one more thing is Object a class cause in the MDN they have mentioned it several times object class, coz we have not been taught about constructors or class it is making me scrolling over everything now and now am really confused what to do and what is this all?
After of more than an hour of trying to understand the MDN of object it feels like i don’t remember anything and i am unable to understand anything what should i do ? It is so frustrating now it feels like i do not even remeber for…in or anything how to understand MDN easily
** https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#Methods_of_the_Object_constructor**

Objects/classes in JS are a way by which the programmer can create their own types (like strings, etc). Every variable and function in JS is an object as well, since everything has a type (string, integer, function-yes that’s a type of data, etc). Another way to look at it is that Object is the most basic data type in JS, on which everything else is built.

2 Likes

okay thanks for the response, but sorry to say i did not get what do you mean to say.
and what are prototypes and object class and MDN is way beyond for me to understand i am unable to understand what’s going on now i am stuck on the Built-in Object Methods for 6 hours now, finding videos and getting new memberships. Can you please help me with that today’s lesson almost made me realize that i haven’t learned or understood anything.

You know that a string is a data type in JavaScript, right? And you know that integer, or int is a data type is JS? Well, an Object is a data type too, just a more basic one. Essentially, Object is the original data type, and on it everything else (strings, integers, etc) is built. The good things about this is that we can actually create our own data types, using an Object as a template.

In JavaScript, pretty much everything is an “object”. There’s a specific type of object, called Object, which you’re likely familiar with:

let my_object = {
    "some_key" : "some value"
    }

There are no “classes” in JavaScript, only objects and prototypes.

The prototype is the mechanism by which instances of a particular object inherit their attributes and methods.

Let’s consider a simple string:

let new_string = "This is a string object";
console.log(typeof(new_string)); // output: "string"

Here we have created a new instance of a String object. Thanks to the String prototype, our new_string object inherits some methods which we can use to work with the string:

let new_string = "This is a string object";
console.log(typeof(new_string)); // output: "string"

// inherited methods below
let ns_includes = new_string.includes("string"); // value: true

let ns_uppercase = new_string.toUpperCase(); // value: "THIS IS A STRING OBJECT"

// a numerical example, but still using a String object
let my_number = "2034399002125581";
let last_four_digits = my_number.slice(-4);
let masked_number = last_four_digits.padStart(my_number.length, "*");
console.log(masked_number); // output: ************5581

// thanks MDN for the above example.

All these methods - includes(), toUpperCase(), slice(), and padStart() - are inherited from the String prototype.

What you’re seeing in the MDN docs, for example String.prototype.toLowerCase(), is simply informing you that all instances of a String will have access to that toLowerCase() method because it comes from the prototype. Thanks to that, you can think of it as essentially the “built in” functionality of whatever object you’re using.

Does that make sense?

5 Likes

HOLY, the best explanation thankyou so much for that now finally i can proceed after 3 days thanks alot

If you understand factory functions, then you basically understand classes

1 Like

I think so I understand Factory Functions but what it has to do with classes ? Can you please let me know as well?