Answers for "event when variable value changes javascript"

1

event when variable value changes javascript

var obj = {
  value: '',
  letMeKnow() {
    console.log(`The variable has changed to ${this.testVar}`);
  },
  get testVar() {
    return this.value;
  },
  set testVar(value) {
    this.value = value;
    this.letMeKnow();
  }
}

console.log(obj.testVar)

obj.testVar = 5;
console.log(obj.testVar)

obj.testVar = 15;
console.log(obj.testVar)
Posted by: Guest on July-20-2020

Code answers related to "event when variable value changes javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language