JavaScript Number Properties
Property |
Description |
EPSILON |
The difference between 1 and the smallest number > 1. |
MAX_VALUE |
The largest number possible in JavaScript |
MIN_VALUE |
The smallest number possible in JavaScript |
MAX_SAFE_INTEGER |
The maximum safe integer (253 - 1) |
MIN_SAFE_INTEGER |
The minimum safe integer -(253 - 1) |
POSITIVE_INFINITY |
Infinity (returned on overflow) |
NEGATIVE_INFINITY |
Negative infinity (returned on overflow) |
NaN |
A "Not-a-Number" value |
JavaScript EPSILON
Number.EPSILON
represents the tiny gap between the smallest floating point number larger than 1 and the number 1.
Note :
Number.EPSILON
is an ES6 feature.
It does not work in Internet Explorer.
JavaScript MAX_VALUE
In JavaScript, Number.MAX_VALUE
stands for the biggest number you can have.
Number Properties Cannot be Used on Variables
Number properties belong to the JavaScript Number Object.
These properties can only be accessed as Number.MAX_VALUE
.
Using x.MAX_VALUE, where x is a variable or a value,
will return undefined
:
JavaScript MIN_VALUE
In JavaScript, Number.MIN_VALUE
is like the smallest number you can ever have. It doesn't change; it's always the tiniest number in JavaScript.
JavaScript MAX_SAFE_INTEGER
The code Number.MAX_SAFE_INTEGER
in JavaScript stands for the largest whole number that can be used safely.
The Number.MAX_SAFE_INTEGER
in HTML is equivalent to the number 2 to the power of 53 minus 1.
JavaScript MIN_SAFE_INTEGER
In JavaScript, Number.MIN_SAFE_INTEGER
stands for the smallest whole number that can be safely used in your code.
The number known as Number.MIN_SAFE_INTEGER
is equal to negative two to the power of 53, minus one.
Note :
MAX_SAFE_INTEGER
and
MIN_SAFE_INTEGER
are ES6 features.
They do not work in Internet Explorer.
JavaScript POSITIVE_INFINITY
JavaScript NEGATIVE_INFINITY
JavaScript NaN - Not a Number
NaN
in JavaScript means a special kind of number that's not a valid number.
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Numbers</h1>
<h2>The EPSILON Property</h2>
<p>The gap between 1 and the smallest decimal number larger than 1 in JavaScript is:</p>
<p id="demo"></p>
<script>
let x = Number.EPSILON;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Numbers</h1>
<h2>The MAX_VALUE Property</h2>
<p>The largest possible number in JavaScript is:</p>
<p id="demo"></p>
<script>
let x = Number.MAX_VALUE;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Number Properties</h1>
<p>When you use the Number property on a variable or value, it will return undefined.</p>
<p id="demo"></p>
<script>
let x = 6;
document.getElementById("demo").innerHTML = x.MAX_VALUE;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Numbers</h1>
<h2>The MIN_VALUE Property</h2>
<p>The smallest number possible in JavaScript is:</p>
<p id="demo"></p>
<script>
let x = Number.MIN_VALUE;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Numbers</h1>
<h2>The MAX_SAFE_INTEGER Property</h2>
<p>The maximum safe integer in JavaScript is:</p>
<p id="demo"></p>
<script>
let x = Number.MAX_SAFE_INTEGER;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Numbers</h1>
<h2>The MIN_SAFE_INTEGER Property</h2>
<p>The minimum safe integer in JavaScript is:</p>
<p id="demo"></p>
<script>
let x = Number.MIN_SAFE_INTEGER;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Numbers</h1>
<h2>The POSITIVE_INFINITY Property</h2>
<p id="demo"></p>
<script>
let x = Number.POSITIVE_INFINITY;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Numbers</h1>
<h2>The NEGATIVE_INFINITY Property</h2>
<p>NEGATIVE_INFINITY is returned on overflow:</p>
<p id="demo"></p>
<script>
let x = -1 / 0;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Numbers</h2>
<p>When you divide a number by something that's not a number, you get a result called NaN.</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 100 / "Apple";
</script>
</body>
</html>