Javascript初级(二)

**

Javascript初级(二)

函数声明和函数分类
**

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    /*
     * 函数
     * 函数是由 事件 或者 主动执行
     * */
    //执行
    /*method1();*/
    function method1() {
        console.log("函数执行");
    }
    function method2() {
        console.log("函数执行");
        return true;
    }
    //执行
    var a = method1();
    var b = method2();
    console.log(a, b);


    function fun1(a, b, c) {
        console.log('有参', a, b, c);
    }
    function fun2() {
        console.log('无参');
    }
    fun1(1, 2);
    fun2();


    function fun3(name, age, sex) {
        console.log('姓名:', name);
        console.log('年龄:', age);
        console.log('性别:', sex);
    }

    fun3('小花', 20, '女');

    //无参函数传递值
    function fun4() {
        //使用函数的参数列表对象
        console.log(arguments);
        console.log(arguments[0]);  //key:value
        console.log(arguments[1]);  //key:value
        console.log(arguments[2]);  //key:value
        console.log(arguments.length);
        console.log("参数列表");
    }
    fun4(1, true, 'abc');


    /*
     * 匿名函数
     * */
    //f();//f is not a function
    var f = function () {
        console.log("匿名函数执行");
    }

    //f();

    var f1 = function () {
        console.log('有返回值');
        return '你好';
    }
    var f2 = function () {
        console.log('无返回值');
    }


    var f3 = function (a, b, c) {
        console.log('有参', a, b, c);
    }
    var f4 = function () {
        console.log('无参');
    }

    f3(1, 2, 3);
    f4();


    /*
     * 自执行函数
     * */
    var nn = (function (a, b) {
        console.log("自执行", a, b);

        return 1;
    })(1, 2);

    console.log(nn);
</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值