JavaScript functions
JavaScript function
##Basic concept of function
is a program instruction (statement) that completes a certain function Sets are called functions.Classification of JavaScript functions
1. Custom functions (functions written by ourselves), such as: function funName(){} 2. System functions (functions that come with JavaScript), such as alert function.How to call the function
1. Ordinary call: functionName (actual parameter...) 2. Pass Point to the variable of the function to call: var myVar=function name; myVar(actual parameter...);Function return value
1. When a function has no clear return value, the returned value is "undefined". 2. When a function has a return value, it returns whatever the return value is.var str="window.alert('好好学习');"; eval(str);//eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码。 /*自定义函数*/ function test(str){ alert(str); } window.alert(test);//输出test函数的定义 //函数的调用方式1 test("好好学习"); //函数的调用方式2 var myFunction=test; myFunction("天天向上"); window.alert(myFunction); /*当函数无明确返回值时,返回的也是值 "undefined"*/ var retVal=test("test");//test函数执行完之后,并没有返回值,因此retVal变量接收到的返回值结果是undefined alert("retVal="+retVal);//输出undefined