Can I pass a value out of a javascript function and back to the calling function, e.g.
function updateURL(url, name, param) {
url = url + "&" + name + "=" + param;
}
I want to update url and return the new value.
Is this possible?
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.
What you’re asking for is called “pass-by-reference“. Javascript uses “pass-by-value” for the native types (int, string, etc)—other types are pass-by-reference. For your specific case, I can think of two ways to get what you want. The first is to require callers to pass in an array with a single element and modify that element:
The second method would be to use an attribute on an object: