Calling a function when DOM is updated in Javascript

Solution for Calling a function when DOM is updated in Javascript
is Given Below:

I want to call a function after DOM loading and I’m using the below code :

window.addEventListener('load', () => {
  console.log("DOM is loaded")
});

Now I want to have an event that calls a function or print a string in the console when DOM is updating.
How can I do this?

MutationObserver is what you are looking for, here is the MDN docs link for the same,

Mutation Observer