In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use the function function in JS". In the daily operation, I believe that many people have doubts about how to use the function function in JS. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the function function in JS". Next, please follow the editor to study!
StringArray are all built-in objects in the system (already defined and can be used directly) of course, the same is true of function in js. The function we defined earlier is actually an example of this. In JS, all objects are implemented by functions, whose data type is object. So, the function we defined earlier is also an object.
Several Writing methods of function in js
Copy the code
1functionfn1 (a _ r _ b) {
2returna+b
3}
four
5Universe / indicates the parameter before, followed by the function statement.
6varfn2=newFunction ("a", "b", "returna+b")
seven
8Universe / anonymous function
9varfn3=function (a _ r _ b) {
10returna+b
11}
twelve
thirteen
14console.log (fn1 (1pm 2))
15console.log (fn2 (1pm 2))
16console.log (fn3 (1J2)); / / Note that you must call after the declaration function
Copy the code
In addition, if the function does not have an explicit return value, or if it calls return with no arguments, then the real value it returns is undefined
Copy the code
1functionfn () {
2//.
3}
four
five
6functionfn1 () {
7return
8}
nine
ten
11console.log (fn ()) = undefined); / / true
12console.log (fn1 ()) = undefined); / / true
The difference between function and Function in js
One: in fact, it is the same as our most common method.
Functionfname (test) {alert ("" + test);}
Second: define the function object through the function constructor of Function.
Varfname=newFunction ("test", "alert ('+ test);"); the first parameter actually represents the parameter to be passed into the function, and the second parameter represents the procedure to be executed by the current function. Both parameters are actually of type string. However, we can see that the current content is actually very complicated.
Third: define the variable with only one function keyword definition.
Varfname=function (test) {alert ("" + test);}
At this point, the study on "how to use the function function in JS" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.