zsydgithub hai 1 ano
pai
achega
564a1b78e5
Modificáronse 2 ficheiros con 148 adicións e 0 borrados
  1. 73 0
      es6/1_变量.html
  2. 75 0
      es6/2_变量2.html

+ 73 - 0
es6/1_变量.html

@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+<body>
+  <script>
+
+    /* 
+      let 和 var 的区别
+      1.let没有变量提升
+      2.let 不能重复声明
+      3.let具有块级作用域
+      4.临时失效区   在这个区域内 不允许同名的变量出现
+    */
+    // console.log(a)
+    // var a = 13
+    
+
+    // let b = 10
+    // let a = 20
+    // a = 30
+    // b = 40
+    // console.log(a,b)
+
+
+    // var a = 10
+    // var a = 20
+    // console.log(a)
+
+    // let a = 10
+    // let a = 20
+
+
+    // var a = 10
+    // function fn(){
+    //   console.log(a)
+    //   var a = 30
+    // }
+    // fn()
+
+
+    // let a = 10
+    // function fn(){
+    //   let a = 'abc'
+    //   console.log(a)
+    // }
+    // fn()
+    // console.log(a)
+
+
+    // var a = true
+    // if(a){
+    //   let x = 100
+    //   console.log(x)
+    // }
+    // console.log(x)
+    /* 块级作用域  在这个作用域里面生命的变量  只能声明在它的块或者是包含块里面出现  
+      一旦离开这个作用域 这个变量就不存在
+
+      在块级作用域里面声明的变量 不会污染全局作用域
+      有助于 避免变量命名重复
+    */
+
+
+    // let x = 10
+    // var x = 10
+  </script>
+</body>
+</html>

+ 75 - 0
es6/2_变量2.html

@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+<body>
+  <script>
+    /* 
+    const 和 var的区别
+    1.const 不能重复赋值
+    2.const 不能重复声明
+    3.const 没有变量提升
+    4.const 具有块级作用域
+    5.const 临时失效区
+    */
+    // const a = 100
+    // a = 200
+    // console.log(a)
+
+
+    // const a = 100
+    // const a = 200
+    // console.log(a)
+
+    // console.log(a)
+    // const a = 100
+
+    // const a = 100
+    // function fn(){
+    //   a = 10
+    //   console.log(a)
+    // }
+    // fn()
+
+    // var a = true
+    // if(a){
+    //   const x = 100
+    // }
+    // console.log(x)
+
+
+
+
+    var a = true
+    if(a){
+      var b = 10
+      let x = 100
+    }
+    b = 30
+    x = 10
+    const c = 200
+    function fn(){
+      console.log(b)
+      // console.log(h)
+      // console.log(xx)
+      let xx = 30
+      var b = 300
+      const x = 30
+      console.log(x)
+      console.log(c)
+    }
+    fn()
+    console.log(a,b,x,c)
+
+    // undefined 报错  30 200   true,30,报错,200
+    // undefined 报错  10 200   true,30,报错,200
+    // undefined 报错  30 200   true,30,10,200
+    // undefined 报错  30 200   true,300,报错,200
+
+  </script>
+</body>
+</html>