javascript (nodejs) const variable overridden in callback function

for a few days I have the problem and could not find a solution to it.
I use nodejs and the packages ethers and want to execute code on “pending” transactions.
The problem i face is that, when i declare a const transaction = await provider.getTransaction(tx) at the beginning of my code and do some stuff at some point the data in transaction changes to a new transaction while i am still in the same callback function. How can this happen?

Sample Code:

 provider.on("pending", async (tx) => {
      const transaction = await provider.getTransaction(tx);
      if(!transaction['data'])
          return;
      ... do some stuff with await and setTimeout etc.
      
      let dataArray= formateTransactionDataToArray (transaction['data']); <= error Cannot read property 'data' of null
 });