Is it fine if I don't understand prototypes in Javascript?

Hello!
I have been trying to understand prototypes and inheritance in JS for a few days now and I still can’t understand it. I have read a lot of articles and watched a lot of youtube videos to understand this topic but I still don’t seem to get it.

Is it fine if I just skip this lesson and use classes instead?
I know it might be better to understand this to be more flexible in JS but is it fine if I come back to this after I get better understanding of Javascript?

Thank you.

Hi there @niwanthakaweragoda06!

I’d say yes, it is OK if you don’t understand prototypes right now. They are one of the hardest subjects to understand in JS. Eventually you’ll probably understand them, but don’t let them block you from progressing in your learning.

Classes is the modern way to write JS object/inheritance code anyway. They are basically just syntactic sugar over the top of the inheritance code.

Thank you so much! I was so stressed out about it! I greatly appreciate your help!

You are very welcome!

I’m not commenting on when someone should learn something because we all learn differently. I just want to point out the value of learning prototypes and inheritance.

This article on inheritance, which you’ve probably already read, helped me the most; it is what sort of turned on the light bulb for me.

I started learning JS a few years ago without knowing anything about object-oriented programming with the purpose of building one large application; and I coded using objects only as another data type. After the light came one, I realized that my code was really a bunch of functions attached to the window object and a lot of variables (that needed to persist beyond the life of a function) stored in custom properties of the relevant functions. And, when I needed another instance of something, those variables became arrays spread across all those funcitons. It worked but it was quite a mess.

Once I came across that article, I was able to take that code and divide it up into specific instances of different objects with only the methods that each object required. All those function properties became properties of specific object instances and no arrays were needed any longer to organize them because the methods were inherited and attached to the object and invoked using “this”. Using “this” and the call method made it all work much better and the code cleaner; and far fewer local variables were needed to be declared because they are stored in the objects and referenced using “this”.

The article on this and the call method helped a great deal, too.

Had I known this at the start, I could’ve saved a lot of trouble in altering about 50k lines of code. However, I don’t know if I could’ve understood it without having already gone through building everything as I did first.

After all that, these comments are probably useless but, if you haven’t seen those articles, perhaps they may be helpful and the light bulb will turn on sooner for you than it did for me.

Good luck.

Thank you so much for taking your time to explain this. I will definitely think about it. Thank you.