I have three variables
var r1 = 12;
var r2 = '';
var r3;
I need to make a function convert()
with three parameters as so:
function convert(arg1, arg2, arg3) {
// function body here
}
such that after I run this code
convert(r1, r2, r3)
console.log(r1, r2, r3)
I should get the output:
r2, "empty string", "undefined value"
That is it should changed the values of r1, r2 and r3 to the above values.
Code I tried:
function convert(arg1, arg2, arg3) {
if (arg2 === '') {
arg2 = "empty string";
}
if (arg3 === undefined) {
arg3 = "undefined value";
}
}
and then call convert(r1, r2, r3)
it fails (obviously!) because of arguments are passed as values. But I need to know is there any way to make this function? Also, I have seen this question, so I know about how they are passed, but still, is there any way I can make this work?