I was wondering how does javascript(if possible) access a variable that has the same name as the variable input of the function.
function myfunc(var1)
{
var var1 = "World";
alert(var1);
}
How can I tell the function which var1 to print?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
nnnnnn is correct, I tested it. Arguments that are passed to a function can be accessed in 2 ways, by their parameter name and through the
argumentsvariable.arguments[0]would be the value of the first parameter.In the example below you would expect 2 alerts, the first one saying
"Hello"and the second saying"World". But they both say"World"proving that assigningvar1actually changes the value of the argument being passed to the function.