In ECMAScript 2015 specification, let, class, and const statements at global scope create globals that are not properties of the global object.
However, avoid using the global scope and wrap your code in a scoping function and use local variables to that scoping function, and make your other functions closures within it like this:
Global and Local Variables
How to share a value between two or more script sections?
To share a value between two or more script sections on your web page, you can define a global variable and assign a value to it in one script section, and then access the same variable and its value in another script section.
Here's an example:
<!-- First script section --> <script> window.mySharedValue = "Hello, world!"; </script> <!-- Second script section --> <script> console.log(window.mySharedValue); // Outputs "Hello, world!" </script>
In this example, we're defining a global variable called
mySharedValue in the first script section and assigning a value to it. We can then access the same variable and its value in the second script section by using the