The problem of the scope of formal parameters of js function

(function e(num){
        var num;
        console.log(num);
        num = 10;
    }(100))

Why does it print out to be 100? my understanding is that var num; redefines the num variable. It should be undefined, asking the boss for advice.

Mar.11,2021

existing will not be redeclared, ignoring var .


your way of writing will define num = 100at the beginning, so num has a value


is equivalent to defining num twice in the function body, and the second time without assignment will have no effect.


declaration statement only has declaration function, and undefined

will not be assigned automatically.
Menu