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

Javascript Basic Tutorial: Defining and Calling Functions_Basic Knowledge

WBOY
Release: 2016-05-16 16:19:43
Original
1164 people have browsed it

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template