New Method to make Infinity
!
So... I found a new way to make
Infinity
in Javascript!
This is how:
Using
parseInt()
with.repeat()
! 🤣
Meaning of parseInt()
parseInt()
basically converts a string into Integer. If some invalid string is passed (like: "hi"), it returnsNaN
Meaning of .repeat()
string.repeat()
returns the same string but repeated the number of times given!
Using it to make Infinity
∞!
Code:
parseInt(`${"9".repeat(999)}`)
So if you just use
"9".repeat(999)
It will return something like this:
More the 9's more the number's digits! (But I used999
)Now,
parseInt
converts the string with the999
9's into an integer. The integer is so big that javascript treats it likeInfinity
!Yay we got
Infinity
in javascript!
😳 I found this when trying to make a string with millions of Hi!
s
[New] Easier way
Math.pow(9999, 9999)
Top comments (5)
parseInt(
${"9".repeat(304)}
) returns a number , parseInt(${"9".repeat(305)}
) returns InfinityCuz that's where the number exits the limit
Hence infinity
but that's interesting, because 304 is not power of 2.
btw there is a hard limit on the number you can use in repeat also!
😳