Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a number 010 to a string "010"

Tags:

javascript

While executing some random expressions in console, I just found that

010 + "" returning 8 (even 011,0100.. are returning results by considering octal number system)

What would I have to do if I want to convert a number 010 to a string "010"? Not only for 010 but for every similar numbers. I managed to find a kind of similar explanation for this here. But that is not explaining how to convert it into a exact string version.

like image 218
Rajaprabhu Aravindasamy Avatar asked Feb 12 '16 10:02

Rajaprabhu Aravindasamy


1 Answers

In Javascript 010 is octal literal and converts to 8 in decimal literal. In fact, you should avoid it, as strict mode disallows to use it.

There is no way to distinguish between octal and decimal notation other than parsing function body string :)

like image 184
Cezary Daniel Nowak Avatar answered Oct 03 '22 00:10

Cezary Daniel Nowak