如果计算出最大可能数字之外的数字,则返回无穷大(Infinity)

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 数字</h1>
  6.  
  7. <p>Infinity (或 -Infinity)是 JavaScript 在计算数时超出最大可能数范围时返回的值:</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var myNumber = 2;
  13. var txt = "";
  14. while (myNumber != Infinity) {
  15. myNumber = myNumber * myNumber;
  16. txt = txt + myNumber + "<br>";
  17. }
  18. document.getElementById("demo").innerHTML = txt;
  19. </script>
  20.  
  21. </body>
  22. </html>