Notes
Variables defined with var can be redeclared:
The following code will not give an error since the variable x is redeclared using var
.
var x = 12;
var x = 15;
Variables declared inside a { } block can be accessed from outside the block:
{
var x = 10;
}
// You can use x here
Redeclaring a variable inside a block will also redeclare the variable outside the block:
var x = 5;
// The value of x is 5 here
{
var x = 3;
// The value of x is 3 here
}
// The value of x is 3 here