In JavaScript,
window
is the root of the global scope, meaning, that all values in window
are visible everywhere.The main use-case for window
is sharing values between different parts of your JavaScript.
For example if you set a value in one of your scripts like so:
window.myValue = 'Hello World!';
Then you can access it from any other script on the same page like so:
const value = window.myValue;
console.log(value); // Hello World!