JavaScript Number Properties and Methods



JavaScript Number Properties

  • These number methods can be used on all JavaScript numbers.
Property Description
EPSILON The difference between 1 and the smallest JS number.
MAX_VALUE The largest number possible in JavaScript
MIN_VALUE The smallest number possible in JavaScript
MAX_SAFE_INTEGER The maximum safe integer (25353 - 1)
MIN_SAFE_INTEGER The minimum safe integer -(25353 - 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 difference between 1 and the smallest floating point number.
javascript-number-precisio

Sample Code

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Numbers</h1>
<h2>The EPSILON Property</h2>

<p>The difference between 1 and the smallest floating point number in JavaScript is:</p>
<p id="demo"></p>

<script>
let a = Number.EPSILON;
document.getElementById("demo").innerHTML = a;
</script>

</body>
</html>

Output

JavaScript Numbers
The EPSILON Property
The difference between 1 and the smallest floating point number in JavaScript is:
2.220446049250313e-16

JavaScript MAX_VALUE

  • Number.MAX_VALUE is a constant representing the largest possible number in JavaScript

Sample Code

<!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>

Output

JavaScript Numbers
The MAX_VALUE Property
The largest possible number in JavaScript is:
1.7976931348623157e+308

Number Properties Cannot be Used on Variables

  • Number properties belong to the JavaScript Number Object.
  • Using a Number property on a variable, or value, will return undefined

Sample Code

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Number Properties</h1>

<p>Using a Number property on a variable, or value, will return undefined:</p>

<p id="demo"></p>

<script>
let x = 6;
document.getElementById("demo").innerHTML = x.MAX_VALUE;
</script>

</body>
</html>

Output

JavaScript Number Properties
Using a Number property on a variable, or value, will return undefined:
undefined

JavaScript MAX_SAFE_INTEGER

  • Number.MAX_SAFE_INTEGER represents the maximum safe integer in JavaScript. Number.MAX_SAFE_INTEGER is (253 - 1).

Sample Code

<!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>

Output

JavaScript Numbers
The MAX_SAFE_INTEGER Property
The maximum safe integer in JavaScript is:
9007199254740991

JavaScript MIN_SAFE_INTEGER

  • Number.MIN_SAFE_INTEGER represents the minimum safe integer in JavaScript. Number.MIN_SAFE_INTEGER is -(253 - 1).

Sample Code

<!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>

Output

JavaScript Numbers
The MIN_SAFE_INTEGER Property
The minimum safe integer in JavaScript is:
-9007199254740991

Related Searches to JavaScript Number Properties and Methods