const robot = {
_model: "1E78V2",
_energyLevel: 2,
get energyLevel() {
if (typeof this._energyLevel === "number") {
return `My current energy level is ${this._energyLevel}%`;
} else {
return "System malfunction: cannot retrieve energy level";
}
},
};
console.log(robot.energyLevel);
at line 5 we wrote "number" OK , and its just a string , but how JavaScript knows that "number" have to be a number? how does it understands an English word (string) ?
i have one request , since you are a gold problem solver , if you like = i have created a topic last day but nobody answered , maybe you can answer it here is the topic =