+ 1
What happens when I name a local variable the same thing as an existing global variable??
If I globally declare a variable and then use same name of the variable in a function which could be local variable. Then want will happen??
4 odpowiedzi
+ 1
You'll hide the global variable due local scope is primary.
+ 1
I already gave you the answer.
0
Within a class you can specify the scope with this.* , or base.* (C#).
0
Ok, but what happen when you declare the variable globally and you the name of variable as a parameter in a function.
Suppose var balance = 10500;
and
function steal(balance, amount) {
if(amount < balance) {
balance = balance - amount;
}
return amount;
}
var amount = steal(balance, 1250);