Java script-functions

Source: Internet
Author: User

There must be a return value after the invocation of the function in Java script.

For example:

find the maximum of a set of numbersvar arr = [23,34,45,56,78,89];function Getmax (arr) {var max= arr[0];For (var i=1;i<arr.length;i++) { max= max<arr[i]?arr[i]:max;}return Max;
}Console.log (Getmax (arr));Return (abort the program Exit function or return data and terminate the termination of the program): not only can return data to the outside of the function, you can also return to complete the data, immediately stop the program and exit the program, return after the code is no longer executed. about returnthe functions in JavaScript are more wonderful1. If the function does not show the use of the return statement, then the function has a default return value: Undefined, such as tellstory ();2. If the function uses the return statement, then the value following the return will be the return value of the function with the return value of Getmax ()3. If the function uses the return statement, but return does not have any value, then the return value of the function is also: undefined for example: Getmin ();4. After the function uses the return statement, the function stops and exits immediately after executing the return statement, which means that all other code after the return is no longer executed. 5. The recommended practice is either to have the function always return a value or never return a value. 6. If you want the function to return multiple values, it's best to put them in an array or an objectFour forms of the function: a no parameter no return value: Only the code is reused, or the code of the function segment B no parameter has a return value C parameter no return value as long as there is no return keyword returned data, there is no real return D with the return value (the actual application of the most) function overload is the same function name, However, the number of parameters of a function or the data type of the formal parameter is different, which makes the function overloaded. However, there is no overload of the function in JS. Because if there is a function with the same name in JS, the function that follows will overwrite the previous function. About pre-parsing of functions: Before the program actually executes, all the code is scanned once,The declaration of a variable, the declaration of a function, and the parameter are promoted to the front of the current scope. The function is declared in the same way as the function expression: the difference: 1, the function of the declaration of the function has a name, 2, the function expression in the function has no name, is an anonymous function, the preceding variable name can be regarded as the name of the function, 3, function declaration function when the function is pre-parsing, The declaration of the function is first advanced to the front of the scope. Same point: The function is the same when the call is executed.

Java script-functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.