Class value returns undefined because value has potential to change

I want to make it so that xNotEqualZero is defined based on the output of the function. The function will return the same output before and after the change method is used on the object. Regardless of how many times you call the change function. This is an example of what the code looks like-

class object {
     constructor(x) {
          this.x = x;
          this.xNotEqualZero = isXEqualZero(this.x);
     };
     change() {
          if (this.x > 0) {
               this.x += 1;
          } else if (this.x < 0) {
               this.x -= 1;
          };
     };
};




let objectOne = new object(3);




function isXEqualZero(x) {
     if (x == 0) {
          return true;
     } else {
          return false;
     };
};



//this code is ran every frame
objectOne.change();
//console.log is just the easist way to show the value
console.log(objectOne.xNotEqualZero);

The code above returns undefined instead of the expected true. I have tried to use the static keyword outside of the constructor. Like So-

constructor(x) {
     this.x = x;
};
static xNotEqualZero = isXEqualZero(this.x);

This returns a type error.

Answer

  1. Naming a class object or any other JS type like string or number is not a good idea. Make it something more specific like Counter or similar
  2. When I run your code, I get false as the output
  3. This line should be this.xNotEqualZero = !isXEqualZero(this.x);