So If i am doing:
setInterval(function(){
console.log("1");
},Infinity);
It keeps on logging 1 as if it is a for loop. Why is that behaviour?
When the float/number Infinity needs to be converted to a 32-bit integer value in JavaScript, as it does for setTimeout, it's converted to zero:
console.log(typeof Infinity); // number
console.log(Infinity | 0); // 0
ECMA-262 6e Section 7.1.5
ToInt32 ( argument )The abstract operation
ToInt32convertsargumentto one of 232 integer values in the range −231 through 231−1, inclusive. This abstract operation functions as follows:
- Let number be
ToNumber(argument).ReturnIfAbrupt(number).- If number is NaN, +0, −0, +∞, or −∞, return +0.
- [...]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With