JavaScript 无穷大属性
如果浮点数超过最大限制,JavaScript 无穷大属性会显示无穷大;如果浮点数低于最小限制,则会显示负无穷大。
以下是 JavaScript 无穷大属性的代码 -
示例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .num { font-size: 18px; font-weight: 500; } </style> </head> <body> <h1>JavaScript Infinity property</h1> <div class="num">1.797693134862315E+10308</div> <div class="num">-1.797693134862315E+10308</div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to add and subtract the above floating numbers by 1 respectively </h3> <script> let sampleEle = document.querySelector(".sample"); let num1 = document.querySelectorAll(".num")[0]; let num2 = document.querySelectorAll(".num")[1]; document.querySelector(".Btn").addEventListener("click", () => { num1.innerHTML = +num1.innerHTML + 1; num2.innerHTML = +num2.innerHTML - 1; }); </script> </body> </html>
输出
点击“点击此处”按钮 -
广告