JavaScript Tutorial

JavaScript Number Properties

JavaScript में numbers से जुड़ी कुछ static properties होती हैं, जो हमें maximum/minimum values, constants जैसे Infinity और NaN, और numerical limits को समझने में मदद करती हैं।

इन properties का उपयोग Number object के साथ किया जाता है और ये read-only (immutable) होती हैं।

इस अध्याय में आप सीखेंगे:


🔹 Number Properties – Overview

PropertyDescription
Number.MAX_VALUEसबसे बड़ा positive number जो JS handle कर सकता है
Number.MIN_VALUEसबसे छोटा positive (non-zero) number (negative नहीं)
Number.POSITIVE_INFINITYInfinity को represent करता है
Number.NEGATIVE_INFINITY-Infinity को represent करता है
Number.NaNNaN value को represent करता है (Not-a-Number)
Number.EPSILONदो floating-point numbers के बीच का सबसे छोटा अंतर
Number.MAX_SAFE_INTEGERसबसे बड़ा safe integer (2⁵³ – 1)
Number.MIN_SAFE_INTEGERसबसे छोटा safe integer (-2⁵³ + 1)

🔸 1. Number.MAX_VALUE

console.log(Number.MAX_VALUE);  
// Output: 1.7976931348623157e+308

इससे बड़ा कोई number Infinity बन जाता है।


🔸 2. Number.MIN_VALUE

console.log(Number.MIN_VALUE);  
// Output: 5e-324

यह 0 के सबसे पास का positive number होता है।


🔸 3. Number.POSITIVE_INFINITY & Number.NEGATIVE_INFINITY

console.log(Number.POSITIVE_INFINITY);  // Output: Infinity
console.log(Number.NEGATIVE_INFINITY);  // Output: -Infinity

जब कोई number calculation limit से बाहर हो जाए, तो यह value return होती है।

console.log(1 / 0);   // Infinity
console.log(-1 / 0);  // -Infinity

🔸 4. Number.NaN

console.log(Number.NaN);            // Output: NaN
console.log(isNaN(Number.NaN));     // Output: true
console.log(typeof Number.NaN);     // Output: "number"

NaN का type भी “number” ही होता है। यह तब आता है जब कोई invalid arithmetic हो।


🔸 5. Number.EPSILON

console.log(Number.EPSILON);  
// Output: 2.220446049250313e-16

यह दो floating-point numbers के बीच का सबसे छोटा अंतर है।
Useful when comparing decimal values:

let a = 0.1 + 0.2;
let b = 0.3;

console.log(Math.abs(a - b) < Number.EPSILON);  // Output: true

🔸 6. Number.MAX_SAFE_INTEGER & Number.MIN_SAFE_INTEGER

console.log(Number.MAX_SAFE_INTEGER);  // 9007199254740991
console.log(Number.MIN_SAFE_INTEGER);  // -9007199254740991

इन limits के बाहर वाले integers “unsafe” माने जाते हैं क्योंकि उनकी precision lost हो सकती है।


📋 Summary Table

PropertyApprox. Valueक्या दर्शाता है
Number.MAX_VALUE1.7976931348623157e+308सबसे बड़ा JS number
Number.MIN_VALUE5e-324सबसे छोटा positive number
Number.POSITIVE_INFINITYInfinityअनंत (positive)
Number.NEGATIVE_INFINITY-Infinityअनंत (negative)
Number.NaNNaNNot a Number
Number.EPSILON2.220446049250313e-16Decimal तुलना में अंतर
Number.MAX_SAFE_INTEGER9007199254740991Safe maximum integer
Number.MIN_SAFE_INTEGER-9007199254740991Safe minimum integer

अभ्यास प्रश्न

  1. Number.MAX_VALUE और Number.MAX_SAFE_INTEGER में क्या अंतर है?
  2. JavaScript में Infinity कैसे उत्पन्न होती है? एक उदाहरण दीजिए।
  3. Number.EPSILON का उपयोग क्यों और कब किया जाता है?
  4. नीचे दिए गए code का output क्या होगा? console.log(0.1 + 0.2 === 0.3); console.log(Math.abs((0.1 + 0.2) - 0.3) < Number.EPSILON);
  5. क्या typeof NaN "number" होता है? इसे समझाइए।
  6. Number.MIN_VALUE और 0 में क्या अंतर है?