<script>
// 1. understanding the function function parameters; 2. the return value of the function; 3 scoped variables; 4 from the calling function
// define the function
function test(){
console.log("hellor wold");
};
was test = function () {
console.log('hello world');
};
test();
// function parameters
function add(a,b){
console.log(a+b);
return a+b;
}
var res = add(1,2);
console.log(res)
// arguments define a method to calculate the number of all incoming and
function addAll(){
There res = 0;
// argument: the method implied attributes goal is to pass all the actual parameter set
for(var i=0;i<arguments.length;i++){
res +=arguments[i];
}
return res;
}
console.log(addAll('1,5,65,464,46,4'))
var a = 10; // global variables
// global and local variables is a relative concept
// create block-level scope is not as if for wehll
function test(){
var b = 5; // with respect to the script, he is a local variable
// relative to the internal test method, b can also be said to be a global variable
function in1(){
}
function in2(){
}
};
// callback function: packaging method, the number of an array, are multiplied by 1, the number of the input is multiplied by 1 plus 2
was arr = [1,2,3];
function multiply(ar,callback){
for(var i=0;i<ar.length;i++){
ar[i] =callback(ar[i]*2);
}
}
multiply(arr,function(a){
return a+1;
});
//View Results
for(var i=0;i<arr.length;i++){
console.log (arr [i], 'which is a callback function')
}
// Self-adjusting function: one-time task processing method for loading tasks, rendering tasks, add a listener
( function(){
the console.log ( 'which is a function call from');
})();
</script>