如何在JavaScript中检查值是否为安全整数?
安全整数是表示为IEEE-754双精度数的整数。那将意味着从(253-1)到-(253-1)的整数。若要在JavaScript中检查值是否为安全整数,请使用isSafeInteger()方法。
示例
您可以尝试运行以下代码来检查值是否为安全整数。对于安全整数和整数,它返回true-
<!DOCTYPE html>
<html>
<body>
<script>
document.write("Checking for Safe Integer...");
document.write("<br>"+Number.isSafeInteger(765));
document.write("<br>"+Number.isSafeInteger(-765));
document.write("<br>"+Number.isSafeInteger('765'));
document.write("<br>"+Number.isSafeInteger(false));
document.write(Number.isSafeInteger(Math.pow(2, 53) - 1));
</script>
</body>
</html>热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短