在乘法运算时,JavaScript 会尝试把字符串转换为数字

  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 x = "100";
  13. var y = "10";
  14. var z = x * y;
  15. document.getElementById("demo").innerHTML = z;
  16. </script>
  17.  
  18. </body>
  19. </html>