简体   繁体   中英

What is purpose of assign value in the function?

I'm a BEGINNER so try please explain with simple words.

The source of my code

What is the purpose of line 3 here:

function sumAndMultiply(a,b,c) { 

        var sumAndMultiplyArray = []
    
        aPlusB = sum(a, b)[0];   //line3
    
        var finalSum = sum(aPlusB, c)[0]; 
    
        sumAndMultiplyArray[0] = finalSum;

        return sumAndMultiplyArray;
    
        }
    sumAndMultiply(4,7,5);

Is it is wrong to make it like that:

function sumAndMultiply(a,b,c) { 

        var sumAndMultiplyArray = []
        
        var finalSum = sum(a, b, c)[0]; 
    
        sumAndMultiplyArray[0] = finalSum;

        return sumAndMultiplyArray;
    
        }
    sumAndMultiply(4,7,5);

The sum function just receive two parameters, the third parameter c will be ignored and won't be summed up.

EDIT:

The purpose of line three is to tell the computer to save the resulting value of calling function sum with params a, b into a new variable called finalSum. This can be achieve in one line, but you should know that ease of read is way more important than compact code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM