Learning materials: http://www.runoob.com/js/js-function-definition.html
Javascriptfunction Definition
JavaScript uses the keyword function to define functions.
A function can be defined by a declaration, or it can be an expression.
Arguments Object
The JavaScript function has a built-in object arguments object.
The argument object contains an array of arguments for the function call.
In this way you can easily find the value of the last parameter
<!DOCTYPE HTML><HTML><Body><PID= "Demo"></P><Script>/*function MyFunction () {var i,max=0;for (i=0;i<arguments.length;i++) {if (Arguments[i]>max) {max=arguments[ I];}} return Max;} document.getElementById ("Demo"). Innerhtml=myfunction (4,5,6,33);*/functionSumAll () {varI,sum=0; for(i=0; I<Arguments.length;i++) {sum+=arguments[i];}returnsum;} document.getElementById ("Demo"). InnerHTML=SumAll (1,2,3,4,5)</Script></Body></HTML>View Code
Closures:
<!DOCTYPE HTML><HTML><Body><Buttontype= "button"onclick= "myFunction ()">Fuck Me</Button><PID= "Demo"></P><Script>/*var counter=0;function add () {return counter+=1;} function MyFunction () {document.getElementById ("demo"). Innerhtml=add ();}*//*document.getElementById ("Demo"). Innerhtml=add (); function add () {var counter=0;function plus () {counter+=1;} Plus (); return counter;}*/varAdd=(function (){varcounter=0;return function(){returncounter+=1;}}) ();functionmyFunction () {document.getElementById ("Demo"). InnerHTML=add ();}</script<!--Variable add specifies the return character value of the function self-invocation. The self-invocation function executes only once. Set the counter to 0. and returns a function expression. The add variable can be used as a function. The great part is that it can access the counter of the scope of the function. This is called a JavaScript closure. It makes it possible for a function to have a private variable. Counters are protected by the scope of anonymous functions and can only be modified by the Add method. --></Body></HTML>View Code
Closures are functions that can access variables in the scope of the previous function, even if the previous function has been closed.
JS function Note