如果计算出最大可能数字之外的数字,则返回无穷大(Infinity)
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript 数字</h1>
- <p>Infinity (或 -Infinity)是 JavaScript 在计算数时超出最大可能数范围时返回的值:</p>
- <p id="demo"></p>
- <script>
- var myNumber = 2;
- var txt = "";
- while (myNumber != Infinity) {
- myNumber = myNumber * myNumber;
- txt = txt + myNumber + "<br>";
- }
- document.getElementById("demo").innerHTML = txt;
- </script>
- </body>
- </html>