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 value
let num:number = Number.MAX_VALUE
// logout this value
console.log(num) // 1.7976931348623157e+308
// compare with infinity
console.log(Number.MAX_VALUE > Number.POSITIVE_INFINITY) // false
console.log(Number.MAX_VALUE > Number.NEGATIVE_INFINITY) // true
// add another value to it
console.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_VALUE and positive infinity, and then negative infinity.
  • Line 12: We multiply Number.MAX_VALUE by 1,000,000. This returns an infinity because any number larger than this method is represented as infinity.

Free Resources