Here is my snippet. Container is an ul element and div is its parent and scrollable. The code contains a resizeObserver function that monitor the size of ul container element. My problem is how can I make variable val global in (console.log('The global variable is: ' + val);) and access it from outside of the function? When I run snippet, the error says this val is not defined. I replaced it with an array and no chance.
  const container = $("#contacts")[0];
  const div = $(".scrollable.scrollable-y")[5];
  let resizeObserver = new ResizeObserver((entries) => {
     for (entry of entries) {
         div.scrollTop = div.scrollHeight;
         var val = div.scrollHeight;
     }
  });
  resizeObserver.observe(container);
  console.log('The global variable is: ' + val);
UPDATE: ok, I read the question and answers. Now, how can I pass a callback to resizeobzerver?
