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

  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. document.getElementById("demo").innerHTML = "结果是:" + x + y;
  15. </script>
  16.  
  17. </body>
  18. </html>