zsydgithub 2 年之前
父節點
當前提交
dd1669ad7c
共有 4 個文件被更改,包括 163 次插入0 次删除
  1. 51 0
      9_es6/1_let.html
  2. 22 0
      9_es6/2_变量提升.html
  3. 41 0
      9_es6/3_const.html
  4. 49 0
      9_es6/4_解构赋值.html

+ 51 - 0
9_es6/1_let.html

@@ -0,0 +1,51 @@
+<!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、临时失效区  在这个区域内  不允许同名的变量出现
+      4、let具有块级作用域
+    */
+    // var a = 10;
+    // var a = 20;
+    // console.log(a)
+
+    // let b = 10;
+    // let b = 20;
+    
+    // let b = 10;
+    // function fn(){
+    //   console.log(b)
+    //   b = 'abc'
+    // }
+    // fn()
+    // console.log(b)
+
+    // var a = 10;
+    // function f1(){
+    //   console.log(a)
+    //   var a = '123'
+    // }
+    // f1()
+    // console.log(a)
+    // console.log(a)
+    // let a = 123
+
+
+    var a = true
+    if(a){
+      let x = 100
+    }
+    console.log(x)
+  </script>
+</body>
+</html>

+ 22 - 0
9_es6/2_变量提升.html

@@ -0,0 +1,22 @@
+<!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>
+    /* 
+      变量提升
+      通过var 定义的变量  会在当前作用域最上方定义这个变量 但是没有赋值
+    */
+    console.log(a)
+    var a = 10
+
+    console.log(b)//报错
+    let b = 20
+  </script>
+</body>
+</html>

+ 41 - 0
9_es6/3_const.html

@@ -0,0 +1,41 @@
+<!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
+      1、不能重复声明
+      2、没有变量提升
+      3、临时失效区
+      4、块级作用域
+    */
+    // const a = 100;
+    // console.log(a)
+    
+    // const a = 100
+    // a = 200 
+    // console.log(a)
+
+    // console.log(a)
+    // const a = 100
+
+    // const a = 100
+    // function fn(){
+    //   console.log(a)
+    //   const a = 10
+    // }
+    // fn()
+      var a = true
+    if(a){
+      const x = 100
+    }
+    console.log(x)
+  </script>
+</body>
+</html>

+ 49 - 0
9_es6/4_解构赋值.html

@@ -0,0 +1,49 @@
+<!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>
+    var arr = [1,2,3]
+    console.log(arr)
+    var [a,b,c] = [4,5,6]
+    console.log(a,b,c)
+
+
+    var obj = {
+      name:'zs',
+      age:18,
+      eat:function(){
+        console.log('吃')
+      }
+    }
+    var {age,name,eat} = obj
+    console.log(age,name,eat)
+
+    var str = 'ab'
+    var [x,y,z] = str
+    console.log(x,y,z)
+    console.log(x)
+    console.log(y)
+    console.log(z)
+
+
+    function fn(name,age){
+      console.log(name,age)
+    }
+    fn({name:'zs',age:20})
+
+    function fn2(){
+      return{
+        name:'zs',age:18
+      }
+    }
+    var {age} = fn2()
+    console.log({age})
+  </script>
+</body>
+</html>