被零除会生成 Infinity

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 数字</h1>
  6.  
  7. <p>除以 0(零)也会生成 Infinity:</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var x = 2/0;
  13. var y = -2/0;
  14. document.getElementById("demo").innerHTML = x + "<br>" + y;
  15. </script>
  16.  
  17. </body>
  18. </html>