I'm reading through JavaScript Succinctly (a free ebook from Syncfusion), and there's a section entitled "Redefining function parameters" which I don't quite understand. Wondering if someone could explain what's going on.
var foo = false;
var bar = false;
var myFunction = function(foo, bar) {
arguments[0] = true;
bar = true;
console.log(arguments[0], bar);
}
myFunction();
I was under the impression that function parameters, whatever they're called, are locally scoped variables -- even if the parameter name is also the name of a globally scoped variable. So, the above code, rather than 'redefining' the function parameters is just defining the parameters. Since, if, after the function is called, if you log bar
to the console, it logs false
. So, yeah, I'm a little confused here. Is the book wrong or am I confused about parameters' names and variables?