数字和数字字符串相加也会产生连接的字符串

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 数字</h1>
  6.  
  7. <p>如果数字和数字字符串相加,结果将是级联字符串:</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var x = 10;
  13. var y = "20";
  14. var z = x + y;
  15. document.getElementById("demo").innerHTML = z;
  16. </script>
  17.  
  18. </body>
  19. </html>