OOPS in JavaScript

Bhaiya,
we have seen a couple of ways for oops in javascript (declaring class and objects). Which is the most preferred way.

ex1: function fruit(taste,color){this.taste=taste;this.color=color;}

ex2:- class fruit{ fruit(taste,color){ this.taste=taste;this.color=color;} }

Which one of these is the correct or better way.

Read this answer: https://stackoverflow.com/a/30783368/8183406
There is no preferred way as such. Both have advantages/disadvantages. You can use any way.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.