jasongr
09-27-2004, 05:36 AM
Hello
I was wondering if it is possible to pass a variable by reference in JavaScript.
I was looking for it in my book, but couldn't find it.
Here is what I am trying to do:
var param = 'Success';
test(param);
function test(param) {
param = 'Success';
if (condition1) {
param = 'Failure';
return;
}
// return some value
}
alert(param);
I would param to change to 'Failure' if the condition is true.
I cannot use the return value, because it is used to return a valid value from the function.
I don't want to use global variables
thanks
I was wondering if it is possible to pass a variable by reference in JavaScript.
I was looking for it in my book, but couldn't find it.
Here is what I am trying to do:
var param = 'Success';
test(param);
function test(param) {
param = 'Success';
if (condition1) {
param = 'Failure';
return;
}
// return some value
}
alert(param);
I would param to change to 'Failure' if the condition is true.
I cannot use the return value, because it is used to return a valid value from the function.
I don't want to use global variables
thanks