-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Web APIs
Web API Intro
Web Validation API
Web History API
Web Storage API
Web Worker API
Web Fetch API
Web Geolocation API
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Graphics & Charts
JavaScript numbers may look simple on the surface, but internally they follow strict rules related to size, precision, and special values. To help developers understand and work safely within these limits, JavaScript provides several built-in Number properties. These properties act as constants that describe numeric boundaries and special numeric states. They are especially important when you are working with large values, financial calculations, validation logic, or edge cases that can easily break normal calculations.
In this chapter, you will learn what JavaScript number properties are, why they are important, how each major number property works, detailed practical examples, common mistakes developers make, best practices, and real-world use cases.
Number properties are predefined, read-only values provided by JavaScript through the global Number object. Unlike number methods, which are called on individual numeric values, number properties are accessed directly using Number.propertyName.
console.log(Number.MAX_VALUE);
These properties give information about the limits and special states of numbers in JavaScript. Since they are constants, their values cannot be changed.
JavaScript uses a floating-point system to store numbers. Because of this, numbers have limits in terms of size and precision. Number properties help you:
Understand how large or small a number can be
Avoid precision loss in calculations
Detect invalid numeric operations
Safely validate user input
Prevent overflow and underflow errors
Decide when to use BigInt instead of Number
Ignoring number properties can lead to silent bugs, especially in applications dealing with money, statistics, or large datasets.
Number.MAX_VALUE represents the largest positive numeric value that JavaScript can represent.
console.log(Number.MAX_VALUE);
If a calculation results in a value larger than Number.MAX_VALUE, JavaScript returns Infinity.
let value = Number.MAX_VALUE * 2;
console.log(value); // Infinity
This property is useful when checking for overflow conditions.
let salary = 1e308;
if (salary > Number.MAX_VALUE) {
console.log("Value exceeds maximum limit");
}
Number.MIN_VALUE represents the smallest positive number greater than zero that JavaScript can represent.
console.log(Number.MIN_VALUE);
This value is extremely close to zero, but it is not zero and not negative.
A common misunderstanding is thinking MIN_VALUE means the most negative number, which is incorrect.
let tinyValue = 5e-324;
if (tinyValue < Number.MIN_VALUE) {
console.log("Value is too small to represent");
}
Number.MAX_SAFE_INTEGER defines the largest integer that can be safely represented without losing precision.
console.log(Number.MAX_SAFE_INTEGER); // 9007199254740991
Beyond this limit, JavaScript can no longer guarantee accurate integer calculations.
let a = Number.MAX_SAFE_INTEGER + 1;
let b = Number.MAX_SAFE_INTEGER + 2;
console.log(a === b); // true (unexpected)
let studentRollNumber = 9007199254740992;
if (studentRollNumber > Number.MAX_SAFE_INTEGER) {
console.log("Use BigInt for this value");
}
Number.MIN_SAFE_INTEGER represents the smallest safe negative integer.
console.log(Number.MIN_SAFE_INTEGER); // -9007199254740991
Values smaller than this may lose precision.
let negativeBalance = -9007199254740995;
if (negativeBalance < Number.MIN_SAFE_INTEGER) {
console.log("Unsafe negative integer detected");
}
This property represents positive infinity.
console.log(Number.POSITIVE_INFINITY);
It usually appears as the result of dividing a positive number by zero or when a value exceeds Number.MAX_VALUE.
let speed = 100 / 0;
console.log(speed); // Infinity
if (speed === Number.POSITIVE_INFINITY) {
console.log("Calculation overflow detected");
}
This property represents negative infinity.
console.log(Number.NEGATIVE_INFINITY);
It appears when a negative value grows beyond the minimum representable range.
let depth = -50 / 0;
console.log(depth); // -Infinity
if (depth === Number.NEGATIVE_INFINITY) {
console.log("Negative overflow detected");
}
Number.NaN represents a value that is Not a Number.
console.log(Number.NaN);
It occurs when a numeric operation fails.
let result = "Riya" / 5;
console.log(result); // NaN
NaN is not equal to anything, including itself.
console.log(Number.NaN === Number.NaN); // false
To check NaN, use isNaN().
if (isNaN(result)) {
console.log("Invalid numeric result");
}
let orderId = 1234567890123456;
if (orderId > Number.MAX_SAFE_INTEGER) {
console.log("Order ID is too large");
}
let value = Number.MAX_VALUE * 10;
if (value === Number.POSITIVE_INFINITY) {
console.log("Overflow error");
}
let input = "Ananya" * 10;
if (isNaN(input)) {
console.log("Invalid input detected");
}
let largeNumber = Number.MAX_SAFE_INTEGER + 5;
if (largeNumber > Number.MAX_SAFE_INTEGER) {
console.log("Precision may be lost");
}
let accountBalance = 1e309;
if (accountBalance === Infinity) {
console.log("Balance exceeds limit");
}
Assuming Number.MIN_VALUE is the most negative number
Ignoring safe integer limits
Comparing NaN using equality operators
Not handling Infinity values
Using Number when BigInt is required
Always validate integers using safe integer limits
Use BigInt for extremely large whole numbers
Check for NaN after calculations
Handle Infinity and negative Infinity explicitly
Use number properties in validation logic
Number properties are widely used in real applications such as:
Banking and finance systems
Scientific and engineering calculations
Input validation in forms
Analytics and reporting tools
Large-scale data processing
JavaScript number properties provide crucial insights into how numeric values behave behind the scenes. Properties like Number.MAX_VALUE, Number.MAX_SAFE_INTEGER, and Number.NaN help developers detect overflow, precision loss, and invalid operations. By understanding and using these properties correctly, you can write safer, more predictable, and more reliable JavaScript code, especially when dealing with edge cases and large numerical values.
Q1. How do you print the largest number JavaScript can represent using a number property?
Q2. Which number property would you use to get the smallest possible positive value?
Q3. How do you access the maximum safe integer in JavaScript using a Number property?
Q4. What will Number("abc") return and which property represents it?
Q5. What is the value of 1 / 0 in JavaScript and which property does it relate to?
Q6. How do you check if a number exceeds Number.MAX_SAFE_INTEGER?
Q7. What is the output of console.log(Number.NEGATIVE_INFINITY)?
Q8. What does Number.EPSILON represent in floating-point calculations?
Q9. How do you access the minimum safe integer supported in JavaScript?
Q10. What is the difference between Number.NaN and isNaN() function?
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Web APIs
Web API Intro
Web Validation API
Web History API
Web Storage API
Web Worker API
Web Fetch API
Web Geolocation API
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Graphics & Charts
