You have to do two things: on the one hand, add the check in the constructor, and on the other, avoid that you can modify the parameter later with invalid values. I have rewritten your object definition using the class syntax, for simplicity:
class Sandskill{
constructor(nom, edad, especialidad, comp){
this.nombre = nom;
this.edad = edad;
if(especialidad == 1 || especialidad == 2 || especialidad == 3){
this._especialidad = especialidad;
}else{
throw new Error('Especialidad no válida');
}
this.comp = comp;
this.nombreCompleto = function(){
return this.nombre +" "+this.apellido;
}
}
set especialidad(valor) {
if(valor == 1 || valor == 2 || valor == 3){
this._especialidad = valor;
}
}
get especialidad() {
return this._especialidad;
}
}
var s1 = new Sandskill ("e", "e", "2", "e");
s1.especialidad=4; //será ignorado
console.log(s1.especialidad);