| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <!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 = "str";
- // let 新的变量定义方式
- // let 定义的变量 不能重复定义
- // let a = 10;
- // let a = 1;
- // let b = "a";
- // a = 10;
- // var a ;
- // console.log(a);
- // let 定义的变量 不能在定义前使用 必须先定义再使用
- // a = 10;
- // let a;
- // console.log(a);
- // let 不存在变量提升
- // const 定义常量 不能重复定义 不能在定义前使用 必须先定义再使用
-
- // let a = 10;
- // a = 20;
- // a = "a";
- // console.log(a);
- // const b = 1;
- // b = 2;
- // console.log(b);
- var a = 10;
- let b = "hello";
- console.log(window.a);
- console.log(window.b);
-
-
- // var 存在变量提升
- // 变量提升:在代码执行前会先将 var 把变量定义的部分提升到当前作用域的最顶端
- // var a;
- // console.log(a);
- // a = 10;
- // function fun(){
- // var a
- // console.log(a);
- // a = 10;
- // }
- // console.log(a);
- // fun();
- // var foo;
- // console.log(foo);
- // foo = function(){
- // console.log("hello world");
- // }
- // foo()
- // var foo = function(){
- // console.log("hello world");
- // }
- // 函数提升:在代码执行前会先将函数定义的部分提升到当前作用域的最顶端
- // foo()
- // function foo(){
- // console.log("hello world");
- // }
- // foo();
- // function foo(){
- // console.log("hello world");
- // }
- // var foo = 10;
- // var foo;
- // function foo(){
- // console.log("hello world");
- // }
- // foo();
- // foo = 10;
- </script>
- </body>
- </html>
|