I was wondering if anybody out there could help me understand why the name within the function does not relate to the name variable outside of the function. What if you wanted to change the global variable of name within the function, is there anyway to do it?
var name = "Paul";
function test(name){
name = name || 'You';
console.log(name);
}
test('Mario');
console.log(name);
Update: Thanks for the quick replies guys. So if you run it line by line is this what's happening?
Once you pass Mario into the function it replaces all the instances of name with the name passed to the function? So in turn you get:
"Mario" = "Mario" || 'You';
but if you pass nothing:
test();
Then doesn't name = name? why would it take the || statement?