⊗jsOpBsPD 9 of 60 menu

Declaring Properties Inside Classes in OOP in JavaScript

At the beginning of a class, you can declare what properties this class will have. For example, let's declare that the user will have the property name:

class User { name; show() { return this.name; } }

You can immediately write some value into it:

class User { name = 'john'; show() { return this.name; } }

Let's now create an object of our class:

let user = new User;

Now let's output the initially specified value:

console.log(user.name); // 'john'

Declare properties name and surn in the Student class.

When declaring, add some values ​​to your properties.

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