Classes and constructors for null

class DisplayUserDetails{
  
  constructor(userName, password, confirmPassword){

    this.userName = userName
    this.password = password
    this.confirmPassword = confirmPassword

  }
  getUsername(){
    // console.log(this.userName)
    if (this.userName.length > 10){
      console.log(this.userName)
      return false
    }else{
    return true;
    }
    // console.log(this.userName)
}
  
  getPassword(){

  }
  confirmPassword(){

  }
}
let  userName = prompt("Enter your username")
const username = new DisplayUserDetails(userName, "Mbadady123", "Mbadady123")
console.log(username.getUsername());

hello campers,
please i want the above code to return false or something else anytime a user clicks on cancel on the prompt

After the let userName = prompt("Enter your username") you can check whether or not userName is null If it is, then the user clicked the cancel on the prompt. You can check to see if the userName passed to the class is null and if it is you can have it return whatever you want it.

class DisplayUserDetails{
  
  constructor(userName, password, confirmPassword){
if(userName === null){
  // throw new Error("Please enter a valid username")
  console.log("this is a null value");
  return;
}
    this.userName = userName
    this.password = password
    this.confirmPassword = confirmPassword

  }
  getUsername(){
    // console.log(this.userName)
    if (this.userName.length > 10){
      console.log(this.userName)
      return false
    }else{
    return true;
    }
    // console.log(this.userName)
}
  
  getPassword(){

  }
  confirmPassword(){

  }
}
let  userName = prompt("Enter your username")
// console.log(userName);
const username = new DisplayUserDetails(userName, "Mbadady123", "Mbadady123")
console.log(username.getUsername());

Now this works but throws an error for the below because null.length is not possible. Is it possible i can just return/end the program if user clicks on the cancel without having an error or without it running any other code inside my class

  if (this.userName.length > 10){
      console.log(this.userName)
      return false