E
E
Eugene Pipa2020-06-16 20:55:41
JavaScript
Eugene Pipa, 2020-06-16 20:55:41

How to change an external variable passed to a function?

I have a possibly interesting question.

There is a task in the tutorial Function min(a, b) .
Very unpretentious.

But I decided to complicate it. I took not 2 but 4 numbers.

let A = +prompt('A =', ''),
     B = +prompt('B =', ''),
     C = +prompt('C =', ''),
     D = +prompt('D =', '');
    
function Minmax(X,Y){
    let i,result;
    if (X > Y) {
        i = X; 
        X = Y; 
        Y = i;
    }
    result = `min = ${X}, max = ${Y}`;
    
    return result;
}

Did so.

And the question is this: I want to select the smaller and larger from all the numbers with several function calls, but I'm stuck on whether it is possible to find out which specific external variables I pass into it when calling and change their values?

I don't even know how to search for a ready-made solution, so my first attempt is to ask something.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-06-16
@Pipuss

No. the values ​​of the parameters passed to the function cannot be changed inside the function. You can return a value from a function and assign the returned value to any variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question