函数的新特性

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //es5
    // function fun1(a,b){
    //   if(typeof b === 'undefined'){
    //     b = 'world'
    //   }
    //   console.log(a,b)
    // }

    // fun1('hello','')    //hello
    // fun1('hello')       //hello world
    // fun1('hello','world')//hello world


    // 1. &&
    // 1.1两边条件都为true时,结果才为true;
    // 1.2如果有一个为false,结果就为false;
    // 1.3当第一个条件为false时,就不再判断后面的条件
    // 注意:当数值参与逻辑与运算时,结果为true,那么会返回的会是第二个为真的值;如果结果为false,返回的会是第一个为假的值。

    // 2. ||
    // 2.1只要有一个条件为true时,结果就为true;
    // 2.2当两个条件都为false时,结果才为false;
    // 2.3当一个条件为true时,后面的条件不再判断
    // 注意:当数值参与逻辑或运算时,结果为true,会返回第一个为真的值;如果结果为false,会返回第二个为假的值

    // function fun1(a, b) {
    //   b = b || 'world'
    //   console.log(a, b)
    // }

    // fun1('hello', '')//hello world
    // fun1('hello')//hello world
    // fun1('hello', 'world')//hello world


    // //es6
    // //给形参设置默认值的方式
    // function fun1(a = 'hello', b = 'world'){
    //   console.log(a,b)
    // }
    // fun1()//hello world
    // fun1('hello')//hello world
    // fun1('hello', 'world')//hello world


    // //剩余参数(rest参数),形式为(...变量名)
    // function fun(x,y){
    //   console.log(x,y)
    //   console.log(arguments) //arguments是所有的实参值
    // }

    // fun(1,2,3,4,5,6,7) //1 2      Arguments(7) [1, 2, 3, 4, 5, 6, 7, callee: ƒ, Symbol(Symbol.iterator): ƒ]


    // function fun(x,y,...arg){
    //   console.log(x,y,arg)
    // }

    // fun(1,2,3,4,5,6,7) //1 2 [3, 4, 5, 6, 7]


    
    // function fun(...arg){
    //   console.log(arg)
    // }

    // fun(1,2,3,4,5,6,7) //[1, 2, 3, 4, 5, 6, 7]


  </script>
</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FGGIT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值