Home >Web Front-end >JS Tutorial >How to declare functions in JavaScript

How to declare functions in JavaScript

王林
王林Original
2021-11-02 17:04:354962browse

How to declare functions in JavaScript: Use new to declare functions, such as [varName=new Function([param1Name, param2Name,...paramNName], functionBody);].

How to declare functions in JavaScript

#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(&#39;中秋节放假??&#39;); alert(&#39;result = &#39; +booleanValue);">click</a>

: javascript video tutorial

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more