参数默认值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 形参初始值的默认参数位置靠后
    function add(a,b,c=10){
        return a+b+c;
    }
    console.log(add(1,2))
    // 与解构赋值结合
    function connect({host="127.0.0.1",name}){
        console.log(host)
        console.log(name)
    }
    connect({name:'cdcdcdc'})
    connect({host:'www.baidu.com',name:'cdcdcdc'})
</script>
</html>

 

posted @ 2024-12-25 18:04  鲁班大师智商二百五  阅读(9)  评论(0)    收藏  举报