index.html 721 B

123456789101112131415161718192021222324252627282930
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. //1.默认值c
  12. function add(a, b, c = 5){
  13. return a+b+c;
  14. }
  15. console.log(add(1,2,3))
  16. //2.与解构赋值结合
  17. // host默认值
  18. function connect({host='127.0.0.1',username,password,port}){
  19. console.log(host)
  20. }
  21. connect({
  22. //host:'localhost',
  23. username:'root',
  24. password:'root',
  25. port:3306
  26. })
  27. </script>
  28. </body>
  29. </html>