I am facing a situation where I have to access a javascript variable from the second file to the first one. But unfortunately, I don't want to rearrange the script order (Because this is the situation).
In HTML:
<body>
<script src="frist.js"></script>
<script src="second.js"></script>
</body>
In frist.js:
console.log(foo); // Got access from second file
In second.js:
const foo = "Access me" // Trying to access from first.js