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.