A numeric value can be represented using the JavaScript number object. In JavaScript, you may create a number object by using the Number() constructor. Numbers are primitive data types in JavaScript.
Lets take an example
const x = 2;
const y = 1.49;
You may also directly assign a different number to a variable.
var x=2; //integer number
var y=101.89; //floating number
var z=new Number(23); //number object integer value
Constant | Description |
---|---|
MIN_VALUE | returns the smallest possible value |
MAX_VALUE | returns the greatest possible value |
POSITIVE_INFINITY | returns a positive infinity, indicating an overflow value |
NEGATIVE_INFINITY | yields a negative infinity, indicating an overflow value |
NaN | represents the value Not a Number |
const x = 15;
// constructing a number object
const y = new Number(15);
console.log(x); // 45
console.log(y); // [Number: 15]
console.log(typeof x); // "number"
console.log(typeof y); // "object"