title: How to detect added global variables at runtime between two lines of code?
body: <p>How to detect added global variables at runtime between two lines of code ?</p>
  
  <p>I want to be able to tell what variable was added in between two lines of code at runtime without analyzing the source code. Just 1 variable is added.</p>
  
  <p>Example:</p>
  
  <pre><code>"use strict";
  //start
  
  const myVariable = "10"; //detect this new variable
  
  //end
  
  const newVariableAdded = detectWhatIsNew();
  
  // newVariableAdded should be "10" or "myVariable"
  </code></pre>
  
  <p>What I tried so far:</p>
  
  <pre><code>"use strict";
  
  const notNew = Object.getOwnPropertyNames(window);
  
  const detectWhatIsNew = function () {
      let newString;
  
      let key;
      Object.getOwnPropertyNames(window).some(function (key) {
          if (!notNew.includes(key)) {
              notNew.push(key);
              newString = key;
              return true;
          }
      });
      return newString;
  };
  
  
  //start    
  
  const myVariable = "10"; //detect this new variable
  
  //end
  
  const newVariableAdded = detectWhatIsNew();
  
  // newVariableAdded should be "10" or "myVariable"
  </code></pre>