The Number Data Type
To declare a variable of the Number data type, you can simply use the
var keyword followed by the variable name:
var myNumber = 10; var pi = 3.14;
Note: When performing division on two integers, the result will be a floating-point number if there is a remainder. Otherwise, it will be an integer.
var sum = 5 + 3; // Result: 8 var product = 4 * 2; // Result: 8 var quotient = 9 / 2; // Result: 4.5
Type Coercion and Conversion
var result = 10 + "5"; // Result: "105"
If you want to explicitly convert a value to a Number data type, you can use the Number() function:
var strNumber = "10"; var convertedNumber = Number(strNumber); // Result: 10