JavaScript – Numbers

What is the number?

Its an arithmetic value used for counting and making calculations.

What is the Number in Javascript ?

Number is a Javascript built-in object that is used to represent the numeric values.

Numbers in Javascript may be of any type Integer or Floating-point value.

Note :

Number object in Javascript follows IEEE standard for representing floating-point values.

Why is the Number Object used in javascript ?

Number object is used to perform mathematical tasks on numerical values.

Number object is used to perform calculations like counting allows us to implement new workflow ideas.

How to construct a Number Object in javascript ?

There are two ways to construct Date object,

1. By directly assigning numbers to variables.

2. By Number() constructor.

Learn javascript free online !!!

1. By directly assigning numbers to variables.

We can directly assign the numbers to a variable.

The number can be of anything, it can be integer or floating-point value.

Syntax :

```var {variable_name} = {numeric_value};
```

Example :

```<!DOCTYPE html>
<html>
<title>Our title</title>
<script type="text/javascript">
var a = 10; // Numeric value
var b = 37; // Numeric value
var c = 120; // Numeric value
var d = 11.34; // Floating Point value
var e = 19e2; // Exponent value
document.write("The value of a = "+a+"<br/>");
document.write("The value of b = "+b+"<br/>");
document.write("The value of c = "+c+"<br/>");
document.write("The value of d = "+d+"<br/>");
document.write("The value of e = "+e+"<br/>");
</script>
<body></body>
</html>
```

Output :

The value of a = 10

The value of b = 37

The value of c = 120

The value of d = 11.34

The value of e = 1900

2. By Number() constructor.

By using Number constructor we can create number object.

If the numeric value passed in the objext is not a number, Then Javascript will return as NaN(Not a Number).

Syntax :

```var {variable_name} = new Number({numeric_value});
```

Example :

```<!DOCTYPE html>
<html>
<title>Our title</title>
<script type="text/javascript">
var a = new Number(31);
document.write("The value of a = "+a+"<br/>");
var b = new Number("AbdulKalaam");
document.write("The value of b = "+b+"<br/>");
</script>
<body></body>
</html>
```

Output :

The value of a = 31

The value of b = NaN

What are the number constants in Javascript ?

There are five number constants in javascript which are listed below,

1. MIN_VALUE

This returns the largest minimum value.

2. MAX_VALUE

This returns the largest maximum value.

3. POSITIVE_INFINITY

This returns positive infinity, overflow value.

4. NEGATIVE_INFINITY

This returns negative infinity, overflow value.

5. NaN

This returns “Not a Number” value.

There are few methods for Number object listed below.