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

Master js functions

小云云
小云云Original
2018-03-26 17:03:401204browse

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 表达式;]
}

Function definition method;

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


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

Function call:

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

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!

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