Had a little doubt in one case. If I have a variable declared in global scope, I know it gets attached to window object.
var var1 = 'Apple';
If I have a variable declared in a function, that variable is in functional scope.
function testFunc() {
var var2 = 'zebra';
}
But if I invoke a function and pass a parameter, I know an assignment operation happens.
eg 1) function testFunct(param1) {
console.log('which scope is param1');
}
testFunct('Mango');
I know assignment operation var param1 = 'Mango'; happens, but where? at invoking place or when invoked? And what is the scope of param1, global or functional.
And if a global variable was declared and passed in invocation,
eg 2) function someFucntionCall(param) {
console.log('what is the scope of param here');
}
var someVar = 'Merc';
someFucntionCall(someVar); //global variable declared and passed in function invocation
What is the scope of param here? Bit confused in these, couldn't find proper explanation anywhere.