What is Number.MAX_VALUE in TypeScript?
Overview
In TypeScript, Number.MAX_VALUE is a number property that returns the largest number possible in TypeScript. This number exists in JavaScript as well. This is because TypeScript and JavaScript are basically the same, except that TypeScript offers more. Wherever JavaScript runs, TypeScript runs as well.
Syntax
Number.MAX_VALUE
The syntax for Number.MAX_VALUE in TypeScript
Return value
The value returned by this number property is 1.7976931348623157e+308. Any number value more than this is represented as infinity.
Example
Let's understand this better with a code example below:
// create a number value as highest number valuelet num:number = Number.MAX_VALUE// logout this valueconsole.log(num) // 1.7976931348623157e+308// compare with infinityconsole.log(Number.MAX_VALUE > Number.POSITIVE_INFINITY) // falseconsole.log(Number.MAX_VALUE > Number.NEGATIVE_INFINITY) // true// add another value to itconsole.log(Number.MAX_VALUE * 1000000) // Infinity
Explanation
- Line 2: We create a number variable and assign it the value of
Number.MAX_VALUE. - Lines 8 and 9: We check for the greater number between
Number.MAX_VALUEand positive infinity, and then negative infinity. - Line 12: We multiply
Number.MAX_VALUEby 1,000,000. This returns an infinity because any number larger than this method is represented as infinity.