4_块作用域.html 489 B

1234567891011121314151617181920212223
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // if(true){
  11. // var a = 10;
  12. // }
  13. // console.log(a);
  14. // let 存在块作用域
  15. // 块作用域:在{}内的代码就是块作用域
  16. if(true){
  17. let a = 10;
  18. }
  19. console.log(a);
  20. </script>
  21. </body>
  22. </html>