Home > Article > Web Front-end > How to declare functions in JavaScript
How to declare functions in JavaScript: Use new to declare functions, such as [varName=new Function([param1Name, param2Name,...paramNName], functionBody);].
#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.
There are generally four ways to declare functions in JavaScript:
Method 1:
function functionName([parameters]){functionBody};
Method 2: Assign an unnamed function function to a specified variable (var )
var add=function(a, b){}
Method 3: Use new operator to declare function
varName=new Function([param1Name, param2Name,...paramNName], functionBody);
Method 4: Write javascript code directly in the middle of html/Jsp code
For example: write in a hyperlink Recommended learning in
<a href="#" onclick="[javascript:] var booleanValue = confirm('中秋节放假??'); alert('result = ' +booleanValue);">click</a>
The above is the detailed content of How to declare functions in JavaScript. For more information, please follow other related articles on the PHP Chinese website!