Answer the question
In order to leave comments, you need to log in
How to create an object in JS?
Good afternoon.
Tell me how to create an object in jS?
If specified as:
let user = {
name: "John",
age: 30,
};
Answer the question
In order to leave comments, you need to log in
Probably somehow using private variables:
class User {
#proff;
constructor(name, age, proff) {
this.name = name;
this.age = age;
this.#proff = proff;
}
get proff() {
return this.#proff;
}
}
const my_user = new User('name', 29, 'luftwaffe');
console.log(my_user.age); // 29
my_user.age = 92;
console.log(my_user.age); // 92
console.log(my_user.proff); // luftwaffe
my_user.proff= 'kriegsmarine';
console.log(my_user.proff); // luftwaffe
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question