Skip to content

Commit f8d0ac6

Browse files
[Term Entry] JavaScript Number methods: .MIN_VALUE (#7388)
* [Term Entry] JavaScript Number methods: .MIN_VALUE * Update MIN-VALUE.md * minor change * format fix ---------
1 parent 8dc83fd commit f8d0ac6

File tree

1 file changed

+97
-0
lines changed
  • content/javascript/concepts/number-methods/terms/MIN-VALUE

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
Title: '.MIN_VALUE'
3+
Description: 'Returns the smallest positive number representable in JavaScript, greater than 0.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Const'
9+
- 'JavaScript'
10+
- 'Numbers'
11+
CatalogContent:
12+
- 'learn-javascript'
13+
- 'paths/computer-science'
14+
---
15+
16+
The `Number.MIN_VALUE` constant represents the smallest positive numeric value that can be represented in JavaScript, which is greater than `0` but very close to it.
17+
18+
## Syntax
19+
20+
```pseudo
21+
Number.MIN_VALUE
22+
```
23+
24+
**Parameters:**
25+
26+
None
27+
28+
**Return value:**
29+
30+
A number (`5e-324`) which is the smallest positive floating-point value representable in JavaScript.
31+
32+
## Example 1: Comparing tiny numbers with `.MIN_VALUE`
33+
34+
This example checks if a number is smaller than JavaScript's smallest positive value:
35+
36+
```js
37+
const tiny = 1e-324;
38+
console.log(tiny < Number.MIN_VALUE);
39+
```
40+
41+
The output of this code is:
42+
43+
```shell
44+
true
45+
```
46+
47+
This confirms that `1e-324` is smaller than `Number.MIN_VALUE`, meaning JavaScript treats it as effectively zero.
48+
49+
## Example 2: Using `.MIN_VALUE` in scientific precision checks
50+
51+
This example determines if a number is too small to be considered non-zero in physics simulations:
52+
53+
```js
54+
function isEffectivelyZero(num) {
55+
return Math.abs(num) < Number.MIN_VALUE;
56+
}
57+
58+
console.log(isEffectivelyZero(1e-325));
59+
console.log(isEffectivelyZero(1e-320));
60+
```
61+
62+
The output of this code is:
63+
64+
```shell
65+
true
66+
false
67+
```
68+
69+
The function detects when a value is smaller than what JavaScript can reliably represent as a non-zero number.
70+
71+
## Codebyte Example: Handling rounding errors in financial apps with `.MIN_VALUE`
72+
73+
This example uses `.MIN_VALUE` to ignore balances that are too tiny to count as real money:
74+
75+
```js
76+
const balance = 0.0000000000000000000000001;
77+
78+
if (balance < Number.MIN_VALUE) {
79+
console.log('Balance is effectively zero');
80+
} else {
81+
console.log('Balance is non-zero');
82+
}
83+
```
84+
85+
## Frequently asked questions
86+
87+
### 1. Is `Number.MIN_VALUE` negative?
88+
89+
No. It is the smallest positive number JavaScript can represent. It is greater than 0.
90+
91+
### 2. What's the difference between `Number.MIN_VALUE` and `Number.MIN_SAFE_INTEGER`?
92+
93+
`MIN_VALUE` is the smallest positive float value (`5e-324`), while `MIN_SAFE_INTEGER` is the most negative integer that can be accurately represented.
94+
95+
### 3. Why does dividing `Number.MIN_VALUE` sometimes return 0?
96+
97+
When a value becomes smaller than what JavaScript can represent, it underflows to 0.

0 commit comments

Comments
 (0)