Javascript Basics Tutorial: Functions with Return Values

Functions with return values

Sometimes, we want a function to return a value to the place where it was called.

This can be achieved by using the return statement.

When using the return statement, the function will stop execution and return the specified value

Syntax:

function function name (){

Function code ;

}


Let’s write an example

    函数  

As shown in the above code, we define a sum value of 15 Then return the value of sum. At this time, the value of the function is also 15;

We define a variable to receive the value returned by the function

Finally output the value of the variable

The following Let’s write a function with parameters and a return value. The code is as follows:

    函数  


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