| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <!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>
- // js 变量定义方式
- var a = 1;
- let b = 2;
- const c = 3;
- // var 定义的变量可以重复定义
- // var num1 = 10;
- // var num1 = 20;
- // console.log(num1); // 20
- // let、 const 定义的变量不可以重复定义
- // let num2 = 10;
- // let num2 = 20;
- // var 定义变量相当于放置到window对象上(全局变量)
- // var num3 = 10;
- // console.log(window.num3); // 10
- // let、 const 定义的变量不放置到window对象上
- // let num4 = 20;
- // console.log(window.num4); // undefined
- // let vs const
- // let 定义的变量可以修改 (let定义的是变量)
- // const 定义的变量不可以修改 (const定义的是常量)
- // let 和 const 除了一个是常量一个是变量外其他都一致
- // let num5 = 10;
- // num5 = "hello";
- // console.log(num5); // hello
- // const num6 = 20;
- // num6 = "world"; // 报错
- </script>
- </body>
- </html>
|