+ 5

[SOLVED] Js help

I had this challange and cant figure out how it work var x = 1e-1; var y = -String(-x*10); alert(y); // output 1 What is e, what is -String and how this work?

18th Jul 2019, 7:01 AM
PanicS
PanicS - avatar
2 Antworten
+ 2
e means the scientific notation: 1e-1 = 1 * 10^-1 = 0.1 -x * 10 = -0.1 * 10 = -1 Then, it's turned into a string ("-1"), then made negative; which makes it a number again. -(-1) equals 1.
18th Jul 2019, 7:38 AM
Airree
Airree - avatar
+ 6
Thank you Airree
18th Jul 2019, 7:41 AM
PanicS
PanicS - avatar