P
Paul Carey
Hi
I would have expected the following to change the value of a, but just
discovered it doesn't.
var forEach = function () {
var a = "a";
[a].forEach(function (v, i) {
console.log("v=" + v);
v = i;
console.log("v=" + v);
});
console.log("a=" + a);
};
The output is:
v=a
v=0
a=a
I'm not really sure why, I'd be very grateful if someone could
explain.
Thanks
Paul
I would have expected the following to change the value of a, but just
discovered it doesn't.
var forEach = function () {
var a = "a";
[a].forEach(function (v, i) {
console.log("v=" + v);
v = i;
console.log("v=" + v);
});
console.log("a=" + a);
};
The output is:
v=a
v=0
a=a
I'm not really sure why, I'd be very grateful if someone could
explain.
Thanks
Paul