Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Js Number Properties in JavaScript

Js Number Properties in JavaScript

? JavaScript Number Properties

JavaScript provides static properties on the Number object that describe important constants and numeric limits. These are not methods, but read-only values.


? List of Number Properties

PropertyDescription
Number.MAX_VALUELargest possible number (~1.79e+308)
Number.MIN_VALUESmallest possible positive number (> 0, ~5e-324)
Number.POSITIVE_INFINITYSpecial value representing positive infinity
Number.NEGATIVE_INFINITYSpecial value representing negative infinity
Number.NaNNot-a-Number value (e.g. result of 0/0)
Number.MAX_SAFE_INTEGERLargest safe integer in JS (2?³ - 1 = 9007199254740991)
Number.MIN_SAFE_INTEGERSmallest safe integer (-2?³ + 1)
Number.EPSILONDifference between 1 and the smallest value > 1

? Examples

1. Max and Min Value

console.log(Number.MAX_VALUE); // 1.7976931348623157e+308console.log(Number.MIN_VALUE); // 5e-324

2. Infinity

console.log(1 / 0);                  // Infinityconsole.log(Number.POSITIVE_INFINITY); // Infinityconsole.log(Number.NEGATIVE_INFINITY); // -Infinity

3. NaN (Not-a-Number)

console.log(0 / 0);           // NaNconsole.log(Number.NaN);      // NaNconsole.log(isNaN("abc"));    // true

4. Safe Integers

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

5. Number.EPSILON

let a = 0.1 + 0.2;console.log(Math.abs(a - 0.3) < Number.EPSILON); // true

? Notes

  • Number.MAX_VALUE is not the maximum integer, it's the max floating-point number.

  • Numbers larger than MAX_SAFE_INTEGER may result in precision issues.

  • EPSILON is useful for comparing floating point numbers due to rounding errors.


Would you like a comparison between Number and BigInt for large or precise number handling?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql