

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find whether a provided number is safe integer or not in JavaScript?
Javascript has some limitations regarding numbers. Any number should be in a standardized computer network format. If any integer violates this rule, it can't be a safe integer.
The safe integers consist of all integers from -(2^53 - 1) inclusive to (2^53 - 1) inclusive (± 9007199254740991 or ± 9,007,199,254,740,991). Whether to know the given number is a safe integer or not, Number.isSafeInteger() must be used.
syntax
Number.isSafeInteger(num);
This method takes a number as a parameter and evaluates whether the number is in the range of safe integer or not. If the provided number is in the range then true will be displayed as the output else false will be displayed as the output.
Example-1
In the following example, the provided two numbers are in the range from -(2^53 - 1) inclusive to (2^53 - 1). So the Number.isInteger() method has evaluated the numbers as true.
<html> <body> <script> var u = Number.isSafeInteger((Math.pow(2,53))-1); var res = Number.isSafeInteger(-1); document.write(res); document.write("</br>"); document.write(u); </script> </body> </html>
Output
true true
Example-2
In the following example, the provided number is not in the range from -(2^53 - 1) inclusive to (2^53 - 1). So the Number.isInteger() method has evaluated the number as false.
<html> <body> <script> var u = Number.isSafeInteger(-(Math.pow(2,53))-5); document.write(u); </script> </body> </html>
Output
false
- Related Questions & Answers
- How to check whether a value is a safe integer or not in JavaScript?
- How to check whether a number is finite or not in JavaScript?
- Check whether a number is a Fibonacci number or not JavaScript
- How to find whether a browser supports JavaScript or not?
- Find whether a given integer is a power of 3 or not in C++
- How to check whether provided elements in an array have passed a specified condition or not in JavaScript?
- How to check whether a number is prime or not using Python?
- Find whether a given number is a power of 4 or not in C++
- How to check whether a NaN is a NaN or not in JavaScript?
- Program to check whether a number is Proth number or not in C++
- C++ Program to Check Whether a Number is Prime or Not
- C++ Program to Check Whether a Number is Palindrome or Not
- C Program to Check Whether a Number is Prime or not?
- Java Program to Check Whether a Number is Prime or Not
- How to know whether an object is sealed or not in JavaScript?