Function that returns a value

In the function in the previous section, the results are output through "document.write". What if you want to process the results of the function?

We only need to change the "document.write(sum)" line to the following code:

function add2(x,y) { sum = x + y; return sum; //返回函数值,return后面的值叫做返回值。}

You can also store the return value of the calling function through variables, the code is as follows:

result = add2(3,4);//语句执行后,result变量中的值为7。

Note: The parameters and return values in the function are not just numbers, but can also be other types such as strings


Continuing Learning
||
返回值函数
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!