In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to achieve the function return value of javascript, I hope you have something to gain after reading this article, let's discuss it together!
In javascript, the statement that implements the return value of the function is return, with the syntax "return [return value];". Inside the function body, the return value of the function can be set using the return statement; once the return statement is executed, the function is stopped and the value of the expression following return is evaluated and returned.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
The JavaScript function provides two interfaces to realize the interaction with the outside world, in which the parameter is used as the entrance to receive the external information, and the return value is used as the exit to feedback the operation result to the outside world.
Inside the function body, you can use the return statement to set the return value of the function. Once the return statement is executed, the function is stopped and the value of the expression following return is evaluated and returned. If the function does not contain a return statement, the undefined value is returned after each statement in the body of the function is executed.
JavaScript is a weakly typed language, so functions have no type restrictions on the values received and output, and JavaScript does not automatically detect the types of input and output values.
Example 1
The following code defines the return value of a function as a function.
Function f () {return function (xrecoy) {return x + y;}}
Example 2
There is no limit to the parameters of the function, but the return value can only be one; if you want to output multiple values, you can design it through an array or object.
Function f () {var a = []; a [0] = true; a [1] = function (xQuery y) {return x + y;} a [2] = 123; return a; / / return multiple values}
In the above code, the function returns an array of three elements, thus returning multiple worthwhile purposes using a return statement.
Example 3
There can be multiple return statements in the function body, but only one return statement can be executed, so you can use the branch structure to determine the function return value in the function body, or use the return statement to terminate the function in advance.
Function f (typeof y) {/ / if the argument is of a non-numeric type, the function terminates the execution of if (typeof x! = "number" | | typeof y! = "number") return; / / returns the conditional value if (x > y) return x-y; if (x < y) return y-x; if (x * y)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.