How to useUser-Defined Function in Javascript
In this method, we have used the user-defined function along with the loop to double the n until 1 no longer changes the value. This is a completely raw method to print JavaScriptâs highest integer value.
Syntax:
while (n + 1 !== n) {
n *= 2;
}
Example: This example implements the above-mentioned approach
Javascript
const maxInteger = () => { let n = 1; while (n + 1 !== n) { n *= 2; } return n - 1; }; console.log( `Max Safe Integer is: ${maxInteger()}` ); |
Output
Max Safe Integer is: 9007199254740991
What is JavaScriptâs highest integer value that a Number can go to without losing precision?
In this article, we are going to implement a JavaScript program that will return the highest integer value that the number can go to without losing precision.
Below are the three approaches using which we will get the highest integer value without losing precision
Table of Content
- Using Number.MAX_SAFE_INTEGER Constant
- Using Mathematical Operation
- Using user-defined Function
Contact Us