fengchuanyu há 9 meses atrás
pai
commit
8c0394e791

+ 36 - 0
5_ES6/1_新的变量定义关键字.html

@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        // var a = 10;
+        // var a = 20;
+        // b = 10;
+        // var b;
+
+        // let a = 10;
+
+        // var a = 10;
+        // console.log(window.a);
+        // let b = 20;
+        // console.log(window.b);
+
+        // const c = 30;
+
+        // console.log("hello");
+
+
+        let a = 10;
+        a = 20;
+        console.log(a);
+
+        const b = 20;
+        b = 30;
+        console.log(b);
+    </script>
+</body>
+</html>

+ 62 - 0
5_ES6/2_变量提升.html

@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        // a = 1;
+        // console.log(a+1)
+
+
+        // console.log(a);
+        // var a;
+
+        // 变量提升:当前变量的定义部分会提升到当前作用域的最顶端
+
+
+
+        // 作用域链:在寻找使用变量的时候,先从当前作用域中查找,如果有直接使用,如果没有向上一层逐层去找。
+        // var a = 1;
+        // function foo(){
+
+        //     console.log(a);
+        //     var a = 2;
+        // }
+        // console.log(a);
+        // foo();
+        // //===》
+        // var a = 1;
+        // function foo(){
+        //     var a;
+        //     console.log(a);
+        //     a = 2;
+        // }
+        // console.log(a);
+        // foo();
+
+        // var foo = function(){
+
+        // }
+
+        // 函数提升:会将当前函数定义部分提升到当前作用域的最顶端
+        // foo();
+        // function foo(){
+        //     console.log("a");
+        // }
+
+
+        // console.log(foo);
+        // var foo = function(){
+        //     console.log("hello foo");
+        // }
+
+        console.log(a);
+        let a = 10;
+
+
+    </script>
+</body>
+</html>

+ 35 - 0
5_ES6/3_let&const特性.html

@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        // var a = 10;
+        // var a = 20;
+
+        // let a = 10;
+        // let a = 20;
+
+        // function foo(){
+        //     console.log(a);
+        //     let a = 10;
+        // }
+        // foo();
+
+
+        // let 会生成块级作用域  在{}内使用let定义变量就会在当前{}里生成一个内部的作用域 
+        // if(true){
+        //     let a = 10;
+        // }
+        // console.log(a);
+
+        {
+            let b = 10
+        }
+        console.log(b)
+    </script>
+</body>
+</html>