重新声明变量不会破坏值
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript 变量</h1>
- <p>如果您再次声明某个 JavaScript 变量,那么它的值不会丢失。</p>
- <p id="demo"></p>
- <script>
- var carName = "porsche";
- var carName;
- document.getElementById("demo").innerHTML = carName;
- </script>
- </body>
- </html>