JavaScript Number Object - Javascript Objects

What is JavaScript Number Object?

The Number object in JavaScript enables you to represent a numerical date, which can be either integers or floating-point numbers.W can create Number Object using Number () constructor. Generally, you do not need to take care about Number objects because the browser itself converts number literals to instances of the number class.

Syntax:
Below is the syntax for creating a number object −
Instead of number, if you give any non-number as an argument, then the argument will not beconverted into a number, it simply returns NaN (Not-a-Number).

What are JavaScript Number Properties?

The below table provides you the list of each property and their description.
Property
Description
MAX_VALUE
The largest possible value a number in JavaScript can have 1.7976931348623157E+308
MIN_VALUE
The smallest possible value a number in JavaScript can have 5E-324
Nan
Equal to a value that is not a number.
NEGATIVE_INFINITY
A value that is less than MIN_VALUE.
POSITIVE_INFINITY
A value that is greater than MAX_VALUE
prototype
A static property of the Number object. Use the prototype property to assign new properties and methods to the Number object in the current document
constructor
Returns the function that created this object's instance. By default this is the Number object.
In the upcoming sections, we will take a few examples to explain the properties of Number.

What are JavaScript Number Methods?

The Number object in JavaScript contains only the default methods that are a part of each object's definition.
Method
Description
toExponential()
Forces a number to display in exponential notation, even if the number is in the range in which JavaScript normally uses standard notation.
toFixed()
Formats a number with a specific number of digits to the right of the decimal.

toLocalString()

Returns a string value version of the current number in a format that may vary according to a browser's local settings.
toPrecision()
Defines how many total digits (including digits to the left and right of the decimal) to display of a number.
toString()
Returns the string representation of the number's value.
valueOf()
Returns the number's value.
In the upcoming sections, we will have a few examples to explain the methods of Number.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Javascript Objects Topics