Number


What is DataType?

The data type defines the type of data we are using in our program. Data Type tells the compiler or interpreter which data and how the user wants to use it in a program, making it easy to compile that data. Various data types vary according to various languages; the basic ones are Number, float, char etc.

Number (Data type)

Javascript is front end and back end web development language, and it provides various data types and wrapper classes. Number in javascript is a wrapper class used to convert any kind of data type in number format. Number() constructor is used for the conversion mechanism. When Number (value) in a program, it converts String or any other data type in Number format; if it isn't able to do it, then it returns NaN (Not a number).

  • Constructor : Number()

The number Wrapper class contains various methods used to perform various operations on Number data.

Example

Number(‘111’) // Return number 111
Number(‘111’)===111 // return true

Number (‘Knowledge2life’) // Return NaN

Significance of Number Wrapper Class

The wrapper class is very useful while coding for any website, there are various inputs and data of the user, which is a number, but the server gets in string format to change that format and perform an operation on it; Wrapper classes were used. Not only Numbers but also various Wrapper classes were used to convert the data format.

Example No.1:

<html> <body> <h2>Knowledge2life</h2> <p id="demo"></p> <script> let x = 3.14; let y = 3; document.getElementById("demo").innerHTML = x + "<br>" + y; </script> </body> </html>

OUTPUT:

Knowledge2life

Example No.2:

<html> <body> <h4>Knowledge2life</h4> <p id="demo"></p> <script> let x = 123e5; let y = 123e-5; document.getElementById("demo").innerHTML = x + "<br>" + y; </script> </body> </html>

OUTPUT:

Knowledge2life

12300000
0.00123