What is infinity in javascript?
Infinity is a property of the global object , or in other words, a variable in global scope. The initial value of Infinity is Number.POSITIVE_INFINITY . The JavaScript keyword Infinity points to the same internal value as POSITIVE_INFINITY. For practical purposes, "Infinity" can be used interchangeably with "Number.POSITIVE_INFINITY" in your scripts.
alert( Number.MAX_VALUE + Number.MAX_VALUE ); //infinity
alert( -2 * Number.MAX_VALUE ); // Negative infinity
POSITIVE_INFINITY is displayed when a number exceeds the upper limit of the floating point numbers, which is 1.797693134862315E+308 while NEGATIVE_INFINITY is displayed when a number exceeds the lower limit of the floating point numbers, which is -1.797693134862316E+308.
alert(Math.pow(10, 1000)); /* Infinity */
alert(Math.log(0) ); /* Negative Infinity */
POSITIVE_INFINITY vs. MAX_VALUE — The value of the MAX_VALUE property is the largest number your JavaScript interpreter can handle. Larger value will be viewed as POSITIVE_INFINITY.
NEGATIVE_INFINITY vs. MIN_VALUE — The value of the MIN_VALUE property is the smallest (closest to zero) number your JavaScript interpreter can handle, while NEGATIVE_INFINITY is the largest negative number the JavaScript interpreter can represent.
The value of NEGATIVE_INFINITY and POSITIVE_INFINITY are read-only : they cannot be changed by your scripts; they are returned by JavaScript whenever a function or operation returns a number larger than the MAX_VALUE the JavaScript interpreter can handle.
The script below illustrate how the JavaScript interpreter understands the concept of infinity (anything out of bound is infinite).
alert( Number.NEGATIVE_INFINITY === -2 * Number.MAX_VALUE ); //true
The above script return "true" because JavaScript interpreter understands the concept, the negative infinity identical to the negative double of the finite MAX_VALUE property.
Related Topics
- JavaScript Interview Questions (Part2)
- JavaScript Interview Questions (Part3)
- Is JavaScript a true OOP language?
- Advantages and Disadvantages of JavaScript
- Difference Between JavaScript and ECMAScript?
- What is noscript tag?
- Escaping Special Characters in JavaScript
- What is undefined x 1 in JavaScript?
- JavaScript : Logical Operators
- Difference between '=', '==' and '===' operators?
- How to reload a page using JavaScript?
- How to write html code dynamically using JavaScript?
- How to add html elements dynamically with JavaScript?
- How to load another html page from javascript?
- What Is The Disadvantages Using InnerHTML In JavaScript?
- What is Browser Object Model
- How to detect the OS on the client machine in JavaScript?
- Difference between window, document, and screen in Javascript?
- Difference between the substr() and substring() in JavaScript?
- How to replace all occurrences of a string in JavaScript?
- How to test a string as a literal and as an object ?
- What is Associative Array? How do we use it?
- What is an anonymous function in JavaScript?
- What is the use of 'bind' method in JavaScript?
- Pure functions Vs. Impure functions in javascript
- Is Javascript a Functional Programming Language?
- What's the Difference Between Class and Prototypal Inheritance?
- Javascript, Pass by Value or Pass by Reference?
- How to prevent modification of an object in Javascript?
- What is 'this' keyword in JavaScript?
- How Does Function Hoisting Work in JavaScript?
- What do mean by NULL in Javascript?
- What does the delete operator do in JavaScript?
- Event bubbling and Event Capturing in JavScript?
- What is "strict mode" and how is it used in JavaScript?
- What is the difference between .call() and .apply()?
- Entire content of a JavaScript source file in a function block?
- What is an immediately-invoked function expression?
- What is escape & unescape String functions in JavaScript?
- What is the instanceof operator in JavaScript?
- What Are RESTful (REpresentational State Transfer)Web Services?
- What is Unobtrusive JavaScript & Why it's Important?
- What Does JavaScript Void(0) Mean?
- What are JavaScript Cookies?
- Difference between Client side JavaScript and Server side JavaScript
- TypeError: document.getelementbyid(...) is null
- Uncaught TypeError: Cannot read property of undefined In JavaScript
- What's the difference between Null and Undefined?