In JavaScript, the "global scope" refers to the outermost scope that is accessible from everywhere in your code. Variables declared in the global scope are called "global variables" and can be accessed from any other scope.
In a browser environment, the global scope is the window object. So, when you declare a variable in the global scope, you're actually adding a new property to the window object.
However, when you declare a variable with const, let, or var inside a <script> block, it's not automatically global. It's scoped to that <script> block. Here's an example:
<script>
const myVariable = 'Hello, world!';
</script>
<script>
console.log(myVariable);
</script>
In the example above, myVariable is not accessible in the second <script> block because it's not in the global scope.
If you want to declare a global variable inside a <script> block, you can do so by attaching it to the window object:
<script>
window.myVariable = 'Hello, world!';
</script>
<script>
console.log(window.myVariable);
</script>
In the example above, myVariable is a property of the window object, so it's in the global scope and can be accessed from any other <script> block.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: