Mark As Completed Discussion

One Pager Cheat Sheet

  • We can create objects with certain attributes that represent particular instances using a class, 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 Book class stores important attributes such as Title, Publication Year, ISBN, Author Name and Number of Pages in order to create different Book objects with various values.
  • The constructor of a class defines 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 a hardcover or paperback.
  • The output of the console.log() statement is Life of Pi, which is the value of the title attribute of myBook, initialized using its constructor and subsequently set equal to that of myBook2.
  • We can use the class and new keywords in JavaScript to define objects and create instances, respectively, where the methods can refer to and set values of properties, while get and set keywords can clarify the relationship between methods and properties.
  • To successfully create the object, the new keyword needs to be used when creating it, and then the name property 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 features such as Access Modifiers and Accessors to the traditional JavaScript structure of Classes and Objects.
  • The code is written in Typescript due to its syntax and use of the constructor and : 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.