Lowest price ever! Learn Generative AI for 48% less!
Get my discount0
JavaScript
Hello ) Help me to understand that: alert( 20e-1['toString'](2) ); // result = 10
3 Answers
+ 2
Another tricky one.
20e-1 is actually 2.
2['toString'](2) calls the toString() method on the object 2 and converting it to a string. the last catch here is that the parameter 2 passed to toString is the radix in which the string conversion is done.
when you convert 2 to base 2,you get 10.
perhaps this will be clearer:
var x=20e-1;
alert (x.toString(2));
0
And again ) Thank you )
0
Your explanation is very clear.