I am writing a nodejs application (v4.2.4), I have detected some odd behavior.
function A(number) {
this.number = number;
}
for(var i = 0; i < 3; i++) {
const a = new A(i);
console.log(a.number);
}
const b = new A(99);
console.log(b.number);
My intuition coming from Java (and one from FireFox) is that the output should have been
0
1
2
99
However node (and chrome) give me
0
0
0
99
I researched and understood from MSN - a block area that vardoes not have a block area in javascript. Looking further, MSN - const describes a const declaration as having a block scope:
Constants are block-like, like variables defined using the let statement. The value of the constant cannot be changed upon reassignment and cannot be updated.
, Node Chrome ( , , V8) const . ,
, , .
, V8 const , FireFox ? , - ?