Add proper indentation to example code (#23794)
This commit is contained in:
committed by
Manish Giri
parent
521138726b
commit
9621e372d0
@ -5,21 +5,20 @@ title: Global Variables
|
||||
Global variables are declared outside of a function for accessibility throughout the program, while local variables are stored within a function using `var` for use only within that function's [scope](https://developer.mozilla.org/en-US/docs/Glossary/Scope). If you declare a variable without using `var`, even if it's inside a function, it will still be seen as global:
|
||||
|
||||
```javascript
|
||||
var x = 5; //global
|
||||
var x = 5; //global variable
|
||||
function someThing(y) {
|
||||
var z = x + y;
|
||||
console.log(z);
|
||||
}
|
||||
|
||||
function someThing(y) {
|
||||
x = 5; //still global!
|
||||
x = 5; //still a global variable!
|
||||
var z = x + y;
|
||||
console.log(z);
|
||||
}
|
||||
|
||||
|
||||
function someThing(y) {
|
||||
var x = 5; //local
|
||||
var x = 5; //local variable
|
||||
var z = x + y;
|
||||
console.log(z);
|
||||
}
|
||||
|
Reference in New Issue
Block a user