DEV Community

Cover image for 20 crazy ways to get Infinity in javascript
Anatolii
Anatolii

Posted on

20 crazy ways to get Infinity in javascript

I have 0 ideas why you need this in real codding life, but who knows what will be if some crazy guy will ask you in your next interview). For sure thats not all ways, but that's more than normally people know (at least).

Infinity === 1.8e+308 one of the easiest way, but it's about unexpected ways, I guess)

2 ** (1025 ^ true)
Date.now() ** (96 >>> '0')
Array(4).fill(10).reduce((acc,number)=>acc ** number)
Array.from({length:2},(__,idx)=> Math.PI ** 8).map((el,idx,arr)=> arr[idx - 1] ** el)[1]
Number.MAX_VALUE ** (true + 0.08)

+'Infinity'
-'-Infinity'
Number.POSITIVE_INFINITY
-`${Number.NEGATIVE_INFINITY}`
+`${Array.from({length:0xFF},(__,idx)=> idx).join('')}` 

-Math.log(0)
Math.atanh(1)
Math.min(...[])
-Math.max(...[])

true / false
!'' / !!''
((!~~Infinity) + !1)  / ~~Infinity
Math.cosh(0) / !(!!-Math.cosh(0))
!!Array.from({length:1}) / Array.from({length:0})
Enter fullscreen mode Exit fullscreen mode

If you think up a better-unexpected example, just tell in comments, I guess that's will be funny,
Thanks for reading, I so appreciate this ♥.

Top comments (0)