2_变量2.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.const 不能重复声明
  15. 3.const 没有变量提升
  16. 4.const 具有块级作用域
  17. 5.const 临时失效区
  18. */
  19. // const a = 100
  20. // a = 200
  21. // console.log(a)
  22. // const a = 100
  23. // const a = 200
  24. // console.log(a)
  25. // console.log(a)
  26. // const a = 100
  27. // const a = 100
  28. // function fn(){
  29. // a = 10
  30. // console.log(a)
  31. // }
  32. // fn()
  33. // var a = true
  34. // if(a){
  35. // const x = 100
  36. // }
  37. // console.log(x)
  38. var a = true
  39. if(a){
  40. var b = 10
  41. let x = 100
  42. }
  43. b = 30
  44. x = 10
  45. const c = 200
  46. function fn(){
  47. console.log(b)
  48. // console.log(h)
  49. // console.log(xx)
  50. let xx = 30
  51. var b = 300
  52. const x = 30
  53. console.log(x)
  54. console.log(c)
  55. }
  56. fn()
  57. console.log(a,b,x,c)
  58. // undefined 报错 30 200 true,30,报错,200
  59. // undefined 报错 10 200 true,30,报错,200
  60. // undefined 报错 30 200 true,30,10,200
  61. // undefined 报错 30 200 true,300,报错,200
  62. </script>
  63. </body>
  64. </html>