Class property declarations
📖 Scenario: You are creating a simple program to represent a book in a library system. Each book has a title, an author, and a number of pages.
🎯 Goal: You will create a TypeScript class called Book with properties for title, author, and pages. Then you will create an instance of this class and display its details.
📋 What You'll Learn
Create a class called
BookDeclare three properties inside the class:
title (string), author (string), and pages (number)Create a variable called
myBook that is an instance of BookAssign values to the properties of
myBookPrint the book details in the format:
Title: [title], Author: [author], Pages: [pages]💡 Why This Matters
🌍 Real World
Classes with properties are used to model real-world objects in software, like books in a library or products in a store.
💼 Career
Understanding how to declare and use class properties is fundamental for object-oriented programming, which is widely used in software development jobs.
Progress0 / 4 steps