class Person{
constructor(name,age){
this.name = name;
this.age = age;
}
get getName(){
return this.name;
}
set setName(name){
if (typeof name === 'number'){
this.name = name;
}else{
this.name = 'joesy';
}
}
}
const p1 = new Person('jack',9);
console.log(`${p1.name}`);
p1.name = 11;
console.log(`${p1.name}`);
I want to be able to check that the parameter passed into the set method is a number and not a string, but it seems that no matter how I write the if statement inside setName(), calling p1.name = value
will always set value
to x.