函数参数默认值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数参数默认值</title>

    <style>
        div{
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>
<body>
<div id="ad">

</div>
<script>
    //1 形参初始值
    function add(a, b = 3){
        return a + b;
    }
    let result = add(3);
    console.log(result);

    //2 与解构赋值结合
    function connect({host='127.0.0.1',username,password,port=3306}) {
        console.log(host);
        console.log(username);
        console.log(password);
        console.log(port);
    }

    connect({
        username: 'root',
        password:'123456'
    })
</script>
</body>
</html>

相关文章:

  • 2021-06-18
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
  • 2018-07-23
猜你喜欢
  • 2021-10-18
  • 2021-08-31
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
相关资源
相似解决方案