Variable Scope in JavaScript
JavaScript has two types of scopes: global and local. A variable that is declared outside a function definition is a global variable, and its value is accessible and modifiable throughout your program.
A variable that is declared inside a function definition is local. It is created and destroyed every time the function is executed, and it cannot be accessed by any code outside the function.
var x = 10; function xyz(){ var y = 5; }
Here x is the global variable and it hsa global scope. We can access x inside the function and outside of it.
Here y is the local variable and it has local scope. we can only access it inside of the function.