首页 > 其他分享 >ES6-ES11 ES11可选链操作符

ES6-ES11 ES11可选链操作符

时间:2023-03-11 16:11:42浏览次数:58  
标签:ES6 dbHost db 可选链 host ES11 config

原视频

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>可选链操作符</title>
</head>
<body>
    <script>
        // ?.
        function main(config){
            // const dbHost = config && config.db && config.db.host;
            const dbHost = config?.db?.host;

            console.log(dbHost);
        }

        main({
            db: {
                host:'192.168.1.100',
                username: 'root'
            },
            cache: {
                host: '192.168.1.200',
                username:'admin'
            }
        })
    </script>
</body>
</html>

标签:ES6,dbHost,db,可选链,host,ES11,config
From: https://www.cnblogs.com/chuixulvcao/p/17206278.html

相关文章