JavaScript Number.MAX_SAFE_INTEGER Constant
Below is the example of the Number.MIN_SAFE_INTEGER Constant.
- Example:
<
script
type
=
"text/javascript"
>
document.write(Number.MIN_SAFE_INTEGER);
</
script
>
Output:
9007199254740991
The JavaScript Number.MAX_SAFE_INTEGER is a constant number that represents the minimum safe integer. This constant has a value of (253 – 1). Here safe refers to the ability to represent integers and to compare them.
Example:
Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2
The above expression will evaluate to true which is actually mathematically NOT correct.
Syntax:
Number.MAX_SAFE_INTEGER
Return Value: A constant number.
Example 1: Below example illustrates the usage of Number.MAX_SAFE_INTEGER
<!DOCTYPE html> < html lang = "en" > < body > < h1 style = "color: green;" >GeeksforGeeks</ h1 > < script type = "text/javascript" > const a = Number.MAX_SAFE_INTEGER + 1; const b = Number.MAX_SAFE_INTEGER + 2; console.log(Number.MAX_SAFE_INTEGER); console.log(a); console.log(a === b); </ script > </ body > </ html > |
Output:
Example 2: Below example illustrates the usage of the constant Number.MAX_SAFE_INTEGER using Math.pow() function.
<!DOCTYPE html> < html lang = "en" > < body > < h1 style = "color: green;" >GeeksforGeeks</ h1 > < script type = "text/javascript" > const a = Number.MAX_SAFE_INTEGER; const b = -(Math.pow(2, 53) - 1); console.log(a); console.log(b); console.log(a === b); </ script > </ body > </ html > |
Output:
Supported Browsers:
- Chrome 34 and above
- Internet Explorer (Not Supported)
- Firefox 31 and above
- Edge 12 and above
- Safari 9 and above
- Opera 21 and above