The finite uses of Infinity

Adam Crockett 🌀 - Jun 14 '21 - - Dev Community

To my knowledge there a few tricks that you can pull off with Infinity

A number larger than any number is actually pretty useful, as the negative sign and you negative number is then larger than any negative number.

Infinity;
-Infinity;
typeof Infinity; // number
Enter fullscreen mode Exit fullscreen mode
// 1.
"Hello World".substr(4, Infinity);

// 2.
"Hello World".substr(4, -Infinity);
Enter fullscreen mode Exit fullscreen mode

1 outputs o world, usually that's a tiny bit harder, you need to know the length of the string do some bad thing like use an arbitrary large number such as 9e9 although unlikely, it will still fail to account for cases where the string was 9e9 + 1 long, I can't live with that...

2 outputs nothing, because well negative numbers in second position arg of substr

Okay so Infinity is pretty useful for ummm.... Not much let me know what you use it for, I know I have used it from time to time to simplify some problems 🔬

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .