Wednesday, February 12, 2020

Learning JavaScript Number Object with examples


Hello guys! evening and welcome to another episode of my tutorial on JavaScript. In my last tutorial we talked about JavaScript Objects overview, we are still going to continue with JavaScript Objects in this tutorial.

We are going to be looking into one of the JavaScript's Native Object called Number Object. The Number object represents numerical data, either integers or floating-point numbers. In general, you do not need to worry about Number objects because the browser automatically converts number literals to instances of the number class.

Syntax

The syntax for creating a number object is as follows -

var  val = new Number(number);

In the place of number, if you provide any non-number argument, then the argument cannot be converted into a number, it returns NAN (Not-a-Number).

You can also read our tutorial post on: JavaScript For Loop

Number Properties

Here is a list of each property and their description

Sr.No.Property & Description
1MAX_VALUE
The largest possible value a number in JavaScript can have 1.7976931348623157E+308
2MIN_VALUE
The smallest possible value a number in JavaScript can have 5E-324
3NaN
Equal to a value that is not a number.
4NEGATIVE_INFINITY
A value that is less than MIN_VALUE.
5POSITIVE_INFINITY
A value that is greater than MAX_VALUE
6prototype
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
7constructor
Returns the function that created this object's instance. By default this is the Number object.
In the upcoming tutorials, we will take a few examples to demonstrate the properties of Number.

You can also read our tutorial post on: JavaScript while Loop


Number Methods

The Number object contains only the default methods that are a part of every object's definition.

Sr.No.Method & Description
1toExponential()
Forces a number to display in exponential notation, even if the number is in the range in which JavaScript normally uses standard notation.
2toFixed()
Formats a number with a specific number of digits to the right of the decimal.
3toLocaleString()
Returns a string value version of the current number in a format that may vary according to a browser's local settings.
4toPrecision()
Defines how many total digits (including digits to the left and right of the decimal) to display of a number.
5toString()
Returns the string representation of the number's value.
6valueOf()
Returns the number's value.
In the following tutorials, we will have a few examples to demonstrate the methods of Number.

Alright guys, we have come to the end of this tutorial. In my next tutorial i will be explaining the properties of Number with series of examples, so stay tuned.

Don't forget to follow us on our various social media platforms and you can ask questions via the comment box below, thanks for reading and bye for now. 
Share:

0 comments:

Post a Comment