'Can you make javascript realize something like a variable or element has changed?

<script>
  let y = 0
  let x = document.querySelector("p")
  setInterval(function(){y++; x.innerHTML = y},1000)
  x.addEventListener("change",change)
  function change(){console.log("i have changed")}

</script>

the script above is kind of what i'm looking for, this has worked for a input element, but i want a this kind of solution, however i am aware it might not be possible, thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source