Home  >  Article  >  Web Front-end  >  Javascript Basic Tutorial: Defining and Calling Functions_Basic Knowledge

Javascript Basic Tutorial: Defining and Calling Functions_Basic Knowledge

WBOY
WBOYOriginal
2016-05-16 16:19:431117browse

A function is a statement that can be run at any time. Simply put, a function is a set of statements that complete a certain function. It accepts 0 or more parameters.

The basic syntax of the function is as follows

Copy code The code is as follows:

function functionName([arg0,arg1,...argN]){
statement
[return[expression]]
}

Among them, function is the keyword of the custom function, functionName is the function name, arg represents the list of various parameters passed to the function, and each parameter is separated by commas. Parameters can be empty.

statement is a function native and can be any legal code block.

reture expression is the value expression of the returned function, which is also optional. A simple example is as follows.

Copy code The code is as follows:

Function sayName(yname){
Document.write("hello" yname)
}
SayName(112);

In addition, javascript will no longer be executed after rerurn is executed.

Copy code The code is as follows:



There may be multiple returns in a function

Copy code The code is as follows:


The above is the entire content of this article. Do you guys have a new understanding of defining and calling javascript? I hope this article can be helpful to everyone

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