Js this problem

function foo(num) {
    console.log("foo: " + num);//6 7 8 9
    this.countPP;
}

foo.count = 0;

var i;
for(i = 0; i < 10; iPP){
    if(i > 5){
        foo( i );
    }
}
console.log(foo.count);// 0
console.log(count);//NaN

outputs 6, br, 7, 8, and 9, I know, and

outputs 0 because this.count points to the global.
the question is why the hidden test count created is NaN?.

It suddenly occurred to me that
called the foo function and implicitly tried to create a global attribute count,
count = undefined. Undefined PP is NaN?.

Mar.11,2021

this.count is global. If it is not defined, of course undefined PP, is NaN


count is not defined. What you define is foo


function foo(num) {
    console.log("foo: " + num);//6 7 8 9
    this.countPP;// window.countPP  Number(undefined)PP
}
console.log(count);//NaN

count initial value undefined
PP operation on undefined, so that count becomes NaN


undefined count

.
Menu