⊗jsOpAdCM 46 of 60 menu

Classes and modules in OOP in JavaScript

Typically, each class is placed in a separate module. In this case, the name of the module file must match the name of the stored class. Let's place our class User in the corresponding file:

export default class User { #name; constructor(name) { this.#name = name; } getName() { return this.#name; } }

In the file index.js we import our class:

import User from './User.js';

Now we can work with our class in this file:

let user = new User('john');

Place the Employee class in a separate file.

In the index.js file, create an object of this class.

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