Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

typescript

What is Number.MAX_VALUE in TypeScript?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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
Number.MAX_VALUE in TypeScript

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.

RELATED TAGS

typescript

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring