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('好好學(xué)習(xí)');"; eval(str);//eval() 函數(shù)可計(jì)算某個(gè)字符串,并執(zhí)行其中的的 JavaScript 代碼。 /*自定義函數(shù)*/ function test(str){ alert(str); } window.alert(test);//輸出test函數(shù)的定義 //函數(shù)的調(diào)用方式1 test("好好學(xué)習(xí)"); //函數(shù)的調(diào)用方式2 var myFunction=test; myFunction("天天向上"); window.alert(myFunction); /*當(dāng)函數(shù)無(wú)明確返回值時(shí),返回的也是值 "undefined"*/ var retVal=test("test");//test函數(shù)執(zhí)行完之后,并沒(méi)有返回值,因此retVal變量接收到的返回值結(jié)果是undefined alert("retVal="+retVal);//輸出undefined