var e = 15;
function change_value(e){
e = 10;
}
change_value(e);
console.log(e);
The Value of e is still 15.
The e
inside the function scope is different from the e
inside the global scope.
Just remove the function parameter:
var e = 15;
function change_value(){
e = 10;
}
change_value();
console.log(e);
javascript does not use reference for simple types. It use a copy method instead. So you can't do this.
You have 2 solutions. This way :
var e = 15;
function change_value(e) {
return 10;
}
e = change_value(e);
Or this one :
var e = 15;
function change_value() {
e = 10;
}
But note that this solution is not really clean and it will only works for this e
variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With