One Pager Cheat Sheet
- We can create
objectswith certainattributesthat represent particularinstancesusing aclass, which will be explained in this lesson for JavaScript and TypeScript. - Classes provide structure to create objects that store data and define how it is used.
- The
Bookclass stores important attributes such asTitle,Publication Year,ISBN,Author NameandNumber of Pagesin order to create differentBookobjects with various values. - The constructor of a
classdefines the parameters required to create a new object instance and sets values for the attributes of that object. - Calling the
paperbackOrHardcover()method of a Book object will determine whether the book is ahardcoverorpaperback. - The output of the
console.log()statement isLife of Pi, which is the value of thetitleattribute ofmyBook, initialized using its constructor and subsequently set equal to that ofmyBook2. - We can use the
classandnewkeywords in JavaScript to define objects and create instances, respectively, where the methods can refer to and set values of properties, whilegetandsetkeywords can clarify the relationship between methods and properties. - To successfully create the object, the
newkeyword needs to be used when creating it, and then thenameproperty can be printed to the console. - In TypeScript, classes and objects use the same syntax as JavaScript and require that the properties of objects and their types be declared in the class definition and further services like parameter properties and arrow functions can be used to simplify the code.
- All properties in a TypeScript class must be initialized either in the class or the constructor.
- TypeScript adds some
featuressuch as Access Modifiers and Accessors to the traditionalJavaScriptstructure of Classes and Objects. - The code is written in Typescript due to its syntax and use of the
constructorand:notation to declare properties. - Classes and objects allow developers to easily break down a real-world problem into manageable and modular components, making it easier to manage data.

