Home > Web Front-end > JS Tutorial > Master js functions

Master js functions

小云云
Release: 2018-03-26 17:03:40
Original
1208 people have browsed it

This article mainly shares with you the detailed explanation of js functions. It mainly shares with you three methods of function definition and function calling methods. I hope it can help you.

Definition of js function:

Function keyword: function;

Function definition is composed of, keyword, function name plus a set of parameters, and placed in curly brackets Defined by a piece of code that needs to be executed.

Function name: required. Function names must be unique within the same page and are case-sensitive.

Parameters: optional. Used to specify a parameter list.

Function statement body: required. Statements that implement function functions.

Expression: Optional, used to return function expression.

function 函数名([参数1,参数2,]){
函数语句体;
   [ return 表达式;]
}
Copy after login

Function definition method;

方法一
var fun1=new Function('{alert("html")}');
Copy after login
方法二
var fun2=function(){
    alert("css");
}
Copy after login


方法三
function fun3(){
    alert("javascript");
}
Copy after login

Function call:

函数调用;
需要先定义再调用;
<script type="text/javascript">
    function test(str1,str,){
       alert(str1+str2);
   }
   
test();
Copy after login

Related recommendations:

Learn more about js functions

JS function and variable promotion and closure explanation

Knowledge you need to master about js functions

The above is the detailed content of Master js functions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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