in

JAVASCRIPT NUMBER | Introduction To JavaScript Number Object

In this tutorial we will be discussing about JavaScript number object which entails how to use the number object when coding in JavaScript. In our previous tutorial we looked at javascript objects and we discussed how to create and use objects when coding. If you haven’t gone through the tutorial you can do so using the link below.

Read previous tutorial on: JAVASCRIPT OBJECTS | Introduction to Objects in JavaScript

JAVASCRIPT NUMBER OBJECT

The JavaScript number object is used as a numerical date either as an integer or floating point number. Developers most times do not worry about number objects because most web browsers automatically converts number literals to instance of a number class.

What is javaScript Number Object ?

The JavaScript number object is used as a numerical date either as an integer or floating point number. Developers most times do not worry about number objects because most web browsers automatically converts number literals to instance of a number class.

SYNTAX OF NUMBER OBJECT

The below illustration shows the syntax for number objects

var numbVal= new Number(number)

Only number arguments are expected in the place of number. A non-number argument can not be converted to a number and will return NAN as result.

JAVASCRIPT NUMBER PROPERTIES

S/N PROPERTY DESCRIPTION
1 NaN This means “Not a Number”. This is returned when a non number argument is passed in.
2 MIN_VALUE This specifies the smallest possible number value which is 5E-324
3 MAX_VALUE This specifies the largest possible number value which is 1.7976931E+308
4 prototype This is used to assign new properties and methods to the number object
5 NEGATIVE_INFINITY This specifies a value that is lower than the MIN_VALUE
6 POSITIVE_INFINITY This specifies a value that is higher than the MAX_VALUE
7 Constructor This is used to return a function that created the objects instance

JAVASCRIPT NUMBER METHODS

S/N PROPERTY DESCRIPTION
1 toString() This method is use to return a string value of the number value
2 valueOf() This method is use to return the value of the number
3 toExponential() This method is use to display a number in exponential notation
4 toLocalString() This method is use to return a string value of a number in a way that vary with the browsers local setting
5 toPrecision() This is use to determine how many total digit of a number that will be displayed
6 toFixed() This is used to set a number to a fixed or specific number of digits

CONCLUSION

We hope with this short tutorial you are able to understand how to structure and use number objects when coding in JavaScript.

NEXT TUTORIAL: JAVASCRIPT- BOOLEAN

What do you think?

javascript objects

JAVASCRIPT OBJECTS | Introduction to Objects in JavaScript

javascript boolean

JAVASCRIPT BOOLEAN | Introduction to Boolean Object in JavaScript