zsydgithub há 1 ano atrás
pai
commit
583969386e
1 ficheiros alterados com 97 adições e 0 exclusões
  1. 97 0
      es6/6_例题.html

+ 97 - 0
es6/6_例题.html

@@ -0,0 +1,97 @@
+<!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 a = 99; //全局变量 
+    // f();
+    // console.log(a); //输出全局的变量
+    // function f() {
+    //   console.log(a); // undefined  因为var有变量提升 
+    //   var a = 10;  //在局部声明
+    //   console.log(a); // 10
+    // }
+
+    // 输出结果:
+      /* 
+        undefined 10 99 
+      */
+
+
+
+
+
+
+    // let a = 'aaa'; 
+    // console.log(a);
+    // console.log(window.a);//undefined
+    // var b = 'bbb';
+    // console.log(b);
+    // console.log(window.b);
+    // c = 'ccc';
+    // console.log(c);
+    // console.log(window.c);
+
+
+
+    function a() {
+      aa = 'aaaa';
+    }
+    a();
+    console.log(aa);
+
+    // function b() {
+    //   var bb = 'bbbb';
+    // }
+    // b();
+    // // console.log(bb);
+
+    // function c() {
+    //   let cc = 'cccc';
+    // }
+    // c();
+    // console.log(cc);
+
+
+    /* for 设置循环变量的部分  是一个父作用域 */
+    /* 循环体内 是一个单独的子作用域 */
+    // for (let i = 0; i < 3; i++) {
+    //   let i = 'aaa';
+    //   console.log(i);
+    // }
+
+    // for (var j = 0; j < 3; j++) {
+    //   var j = 'bbb';
+    //   console.log(j);
+    // }
+
+    /* 
+      x  
+      aaa   bbb
+      aaa  aaa  aaa    bbb
+      x     bbb
+      aaa   bbb
+    */
+
+
+
+
+
+    for (let i = 0; i < 10; i++) {
+      console.log(i);// 0 1 2 3 4 5 6 7 8 9
+      setTimeout(function () {
+        console.log(i);
+      }, 0);
+    }
+
+  </script>
+</body>
+
+</html>