12 تغريدة 1 قراءة Apr 19, 2023
JavaScript Classes 🚀
👇🧵
Don't forget to bookmarked it for future reference...
Resources used : programiz.com
Classes are one of the features introduced in the ES6 version of JavaScript.
A class is a blueprint for the object. You can create an object from the class.
☆ Creating JavaScript Class
• JavaScript class is similar to the Javascript constructor function, and it is merely a syntactic sugar.
• The constructor function is defined as :
• Instead of using the function keyword, We use the class keyword for creating JS classes.
• Example :
• Here the class keyword is used to create a class. The properties are assigned in a constructor function.
• Now We can create an object.
• Example :
• Here, person1 and person2 are objects of Person class.
• Note : The constructor() method inside a class gets called automatically each time an object is created.
☆ Javascript Class Methods
• While using constructor function, we define methods as :
• It is easy to define methods in the JavaScript class. We simply give the name of the method followed by ().
• Example :
• Note: To access the method of an object, you need to call the method using its name followed by ().
☆ Getters and Setters
• In JavaScript, getter methods get the value of an object and setter methods set the value of an object.
• Similarly, JS classes may include getters and setters. We use the get keyword for getter methods and set for setter methods.
• Example :
End thread 🧵
If you liked this thread:
-RT the first thread and share it with folks on Twitter.
-Follow @personalvipin for more such insightful threads.
Thanks for reading!

جاري تحميل الاقتراحات...