JS函数基础

  1. 匿名函数
var test = function test1() { // 等于function() {} 匿名函数
    console.log('aaa');
    test1(); // 内部可执行
}

console.log(test.name) // test1
test1() // 外部报错
  1. 形实参
function test(a, b) {
    console.log(test.length); // 2形参数量
    console.log(arguments.length); // 3实参数量
}

test(1, 2, 3);
function test(a, b) {
    a = 3;
    console.log(arguments[0]); // 3可以改变实参的值
}

test(1, 2);
function test(a, b) {
    b = 3;
    console.log(arguments[1]); // undefined无法赋值
}

test(1);
function test(a = 1, b = 2) { // Es6出来的
    console.log(a); // 1
    console.log(b); // 3
}

test(undefined, 3);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值