⊗tsSpOpSPr 14 of 37 menu

Static Properties in TypeScript

In TypeScript, you can create special properties that belong to a class rather than an object. Such properties are called static.

Static properties can be called without creating an object, simply by accessing the class in which they are declared. To make a property static, you need to write the keyword static after the access modifier.

Let's define a static property salary in the User class:

class User { public name: string; public static salary: number = 1000; constructor(name: string) { this.name = name; } }

Now let's access this property without creating an object:

console.log(User.salary); // 1000

Add a static property specialty to the Student class. Infer this property without declaring an object.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline