0

How can identify which of the variables are used as Global variables across multiple scripts?  

I am trying to solve an error that occors in a web-page that I didn't write.

The web-page imports many different scripts, written in Vanilla JavaScript.

Appearently, there are a few common variables that are used accross multiple script files, which is the cause for the problem.

Changing all the types from let to var - by using 'replace' (cntl+h on vscode in the combined file) - solved the issue.  

Seems that the former programmer used something like this - Can I access variables from another file?  

Anyway, in order to fix it, I would like to identify which are the common variables and what scripts using them.

What is the best way to do so?

Shir K
  • 523
  • 4
  • 9
  • You can look at https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Proxy – Kornflexx Mar 12 '20 at 09:44
  • First of, how did you replace let -> var? Can you try and focus on those let, and check how are they used? Since that causes the problem right. – Markipe Mar 12 '20 at 09:50

1 Answers1

1

Try LocalStorage concept.

For an example:

let key = 'Item 1';
localStorage.setItem(key, 'Value'); 
localStorage.getItem(key);  //use this syntax any other file it will work.

Else

use require method:

const varName = require('./importYourScript.js')
console.log(varName);

If you are using ECMAScript:

import varName from './importYourScript';
console.log(varName);
PrakashT
  • 763
  • 5
  • 16