+ 5

[SOLVED] Js challange help

Why output is 5 and how this thing with Infinity work? var a = 1 / -Infinity + 5 % Infinity; console.log(a);

15th Jul 2019, 6:21 PM
PanicS
PanicS - avatar
3 Respostas
+ 2
First part 1/-Infinity will be evaluated as 0 (infinity will make it close to 0), second part modulo operator "%" is used =>5 % Infinity and when the first part before "%" is smaller than second it returns it => 5. So finally 0 + 5 => 5.
15th Jul 2019, 6:38 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 4
1/inf = 0 = 1/-inf okay? now 5%inf 5%1=0 5%2=1 5%3=2 5%4=1 5%5 =0 now we goon 5%6=5. 5/6 = remainder 5 5%7 = 5%8 = 5%10 = 5%20 = 5%100 = 5%1000 = 5%anything >5 =5.
15th Jul 2019, 6:35 PM
Oma Falk
Oma Falk - avatar
+ 3
actually there is no infiniy but lim 1/n n->inf write a prog that prints 1/n. becoming bigger and bigger after the same buf n becoming - 100...-1000...-10000. both progs will print a value nearer and neater to 0. The first one from right side and the second one frim left side. but both go nearer and nearer to 0.
15th Jul 2019, 6:43 PM
Oma Falk
Oma Falk - avatar