Types of Scope in JavaScript

Global Scope

Variables declared outside any function or block belong to the global scope. They can be accessed from anywhere in the code.

<script>var globalVar = "I am global"; 

console.log(globalVar); // Accessible here

function test() {

console.log(globalVar); // Accessible inside the function

}

test();


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *