Юзайте эту библиотеку.
https://www.npmjs.com/package/track-changes-js
Пример
// tracked variable
let num = 1;
// add an observer, pass the name and function that returns the variable
trackChanges.addObserver('numObserv', () => num);
// add a handler, pass the name and function that will be called when changing "num"
trackChanges.addHandler('numObserv', numHandler);
/**
create a function that will be called when the variable changes, the function argument will be its changed value
**/
function numHandler(modifiedResult) {
console.log(`Num changed to: ${ modifiedResult }`);
}