Javascript Reference - JavaScript Number Reference








The Number type is the reference type for numeric values. To create a Number object, use the Number constructor and pass in any number.

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">
            var numberObject = new Number(10); 
            document.writeln(numberObject);
    </script>
</head><!--from  ww  w .ja  va 2 s. com-->
<body>
</body>
</html>

Click to view the demo

Property Description
MAX_VALUE Get the largest number possible in JavaScript
MIN_VALUE Get the smallest number possible in JavaScript
NEGATIVE_INFINITY Get negative infinity
NaN Represents a Not-a-Number value
POSITIVE_INFINITY Represents infinity
prototype Allows you to add properties and methods to an object




Number Methods

Method Description
toExponential(x) Converts a number into an exponential notation
toFixed(x) Formats a number with x numbers of digits after the decimal point
toPrecision(x) Formats a number to x length
toString() Converts a number to a string
valueOf() Returns the primitive value of a number