Why 0 is being excluded ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why 0 is being excluded ?

Guys, i’m doing an javascript exercise and i got doubious. When i transformed the number following by 0 to string by adding with empty string, and then output the length. Why the length is not 5 ?? https://code.sololearn.com/W987q2v8qXt4/?ref=app

21st Aug 2019, 3:11 AM
Matheus Rodrigues
Matheus Rodrigues - avatar
2 Answers
+ 2
There is no number start with 0, so it should be 4. If you want 5, you have to declare it to string like '02344' Good Luck ~
21st Aug 2019, 3:15 AM
Uchiha Itachi
Uchiha Itachi - avatar
+ 2
"Never write a number with a leading zero (like 07). Some JavaScript versions interpret numbers as octal(base 8) if they are written with a leading zero." quote from W3Schools https://www.w3schools.com/js/js_numbers.asp; https://code.sololearn.com/Wk3c5vbCl6L2/#html
21st Aug 2019, 4:24 AM
ODLNT
ODLNT - avatar