I am practicing Javascript, so I wrote:
function f(){
console.log(this);
var b=2;
console.log(b);
this.b++;
console.log(b);
b++;
}
f();
console.log(b);
The result surprised me:
/*the console result*/
window
2
2
NaN
In my opinion, this points to f();. b is a private variable for f();. this.b++ and b++ operate on the same variable.
/*the right anwser in my mind*/
f
2
4
TypeError
Please explain why I did not get the expected result.