
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to find whether a provided number is safe integer or not in JavaScript?
Java script provides a Number.isSafeInteger() to check whether the given number is a safe integer or not. If the integer is safe then returns true otherwise it will return false..
JavaScript has some restrictions regarding the number, any number should be in an SCNF standardized computer network format. If a number breaches the rule, then it is not a safe integer.
The reason behind that the number is that JavaScript uses double-precision floating-point format numbers as specified in IEEE 754 and can only safely represent integer b/w −(2^53-1) and (2^53-1)
Example 1
In the following example, we check the two number whether it is safe or not. Number1 is out of range i.e. is not safe the output evaluation is false.The number2 is in range i.e is safe the output evaluation is true.
<!DOCTYPE html> <html> <body> <script> const number1 = Number.isSafeInteger(-Math.pow(2,53)-3); document.write(number1 + "<br>"); const number2 = Number.isSafeInteger(-253); document.write(number2); </script> </body> </html>
Example 2
In the following example, we are passing an array of integers and checking whether the given element is safe or not.
<!DOCTYPE html> <html> <body> <script> const arr = [15, 20, 30, 40, -100, -500]; document.write("{"); for (let index = 0; index < arr.length; index++) { document.write(Number.isSafeInteger(arr[index]) + " "); } document.write("}"); </script> </body> </html>
Example 3
In the following example, data type float is not supported if you pass float value as an argument then evaluation is false. isSafeInteger() method only supports the Integer value in their range otherwise it gives false.
<html> <body> <script> const number1 = Number.isSafeInteger(-0.567); document.write(number1 + " "); const number2 = Number.isSafeInteger(-253.0345); document.write(" " + number2 + " "); const number3 = Number.isSafeInteger(5.583); document.write(" " + number3); const number4 = Number.isSafeInteger(0 / 0); document.write(" " + number4 + " "); const number5 = Number.isSafeInteger(6 - 2); document.write(" " + number5 + " "); const number6 = Number.isSafeInteger(0); document.write(" " + number6); </script> </body> </html>
- Related Articles
- 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?
- How to check whether provided elements in an array have passed a specified condition or not in JavaScript?
- Find whether a given integer is a power of 3 or not in C++
- How to check whether a number is a prime number or not?
- How to Check Whether a Number is Krishnamurthy Number or Not in Java?
- How To Check Whether a Number is Strontio Number or Not in Java?
- How To Check Whether a Number is Tcefrep Number or Not in Java?
- How To Check Whether a Number is Tech Number or Not in Java?
- How To Check Whether a Number Is a Pronic Number or Not in Java?
- How To Check Whether a Number Is a Bouncy Number or Not in Java?
- How To Check Whether a Number is a Evil Number or Not in Java?
- How To Check Whether a Number Is a Fascinating Number or Not in Java?
