Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is 0 less than Number.MIN_VALUE in JavaScript?

Using Node.js, I'm evaluating the expression:

0 < Number.MIN_VALUE 

To my surprise, this returns true. Why is that? And: How can I get the smallest number available for which the comparison works as expected?

like image 662
Golo Roden Avatar asked Oct 28 '14 17:10

Golo Roden


People also ask

What is integer MIN_VALUE in JavaScript?

Number. MIN_VALUE is the smallest positive number (not the most negative number) that can be represented within float precision — in other words, the number closest to 0.

What is the smallest number in js?

JavaScript Number MIN_VALUE MIN_VALUE returns the smallest number possible in JavaScript. Number. MIN_VALUE has a value of 5e-324.

What is 5e-324?

Number. MIN_VALUE is 5e-324 , i.e. the smallest positive number that can be represented within float precision, i.e. that's as close as you can get to zero. It defines the best resolution floats give you. Now the overall smallest value is Number.

What is the largest number in JavaScript?

JavaScript Number MAX_VALUE MAX_VALUE returns the largest number possible in JavaScript. Number. MAX_VALUE has the value of 1.7976931348623157e+308.


2 Answers

Number.MIN_VALUE is 5e-324, i.e. the smallest positive number that can be represented within float precision, i.e. that's as close as you can get to zero. It defines the best resolution floats give you.

Now the overall smallest value is Number.NEGATIVE_INFINITY although that's not really numeric in the strict sense.

like image 189
back2dos Avatar answered Oct 01 '22 06:10

back2dos


Number.MIN_VALUE is equivalent to 5e-324 , which is greater than 0.

like image 29
Mukund Kumar Avatar answered Oct 01 '22 06:10

Mukund Kumar