3_const.html 735 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. /*
  12. const 和 var的区别
  13. 1.const 不能重复声明
  14. 2.不能重复赋值
  15. 3.没有变量提升
  16. 4.临时失效区
  17. 5.const 块级作用域
  18. */
  19. // const a = 100
  20. // a = 200
  21. // console.log(a)
  22. // console.log(a)
  23. // const a = 100
  24. // const a = 100
  25. // function fn(){
  26. // console.log(a)
  27. // const a = 10
  28. // }
  29. // fn()
  30. var a = true
  31. if(a){
  32. const x = 10
  33. }
  34. console.log(x)
  35. </script>
  36. </body>
  37. </html>