重新声明变量不会破坏值

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 变量</h1>
  6.  
  7. <p>如果您再次声明某个 JavaScript 变量,那么它的值不会丢失。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var carName = "porsche";
  13. var carName;
  14. document.getElementById("demo").innerHTML = carName;
  15. </script>
  16.  
  17. </body>
  18. </html>