语法格式

  function 函数名(参数){
结构体
        }
        函数名();

声明并调用

function qqq(){
    console.log(95722);
    console.log(11111);
    console.log(888555);
}


qqq();

2023-06-29T04:25:11.png

调用多次

    function qqq(){
        console.log(95722);
        console.log(11111);
        console.log(888555);
    }


    qqq();
    qqq();

2023-06-29T04:25:33.png

使用参数声明变量

    
function sum(a,b){
    console.log(a + b);
}
sum(3,4);
sum("3",4);

2023-06-29T05:20:21.png
2023-06-29T05:24:01.png

终止执行

 function fun(){
        console.log(111);
        console.log(222);
        return;
        console.log(554);
        console.log(977);
    }
    fun();

2023-06-29T07:15:48.png

函数的返回值

function ss(a,b){
    return a + b;
}
    console.log(ss(1,2));

2023-06-29T07:22:24.png

返回值作为参数

function ss(a,b){
    return a + b;
}
    var qq = ss(3,4);

    console.log(qq);

    console.log(ss(2,ss(3,4)));

2023-06-29T07:32:43.png

变量名调用function函数

var foo = function fun(){
    console.log(1);

};

var foo2 = function (){

    console.log(2);
};

foo();
foo2();

2023-06-29T07:58:08.png

返回结果并相加

2023-08-14T21:50:38.png

function c(q,w){
    return q  +  w;

};


var qw =  c(111,222);

console.log(qw);