jimjim
jimjim

Reputation: 2503

Is using 001 as a number same as 1 in Javascript?

EDIT : This is not a duplicate of the other question as to realise why prepending 0's to numbers can actually result in a different value, this question has nothing to do with Octals, In the other question does the significance of prepending 0's to a number resulting in a different (Octal) value is not obvious.

For code alignment to look nice, I formatted number of lines that would have an integer as an argument from 1,2,3,.. to 01,02,03,...

Are the two indistinguishable in JavaScript? ( please don't mistake 01 with "01" they are different types. anyone knows of any example in any programming language where 1 and 01 will not be the same value?).

Upvotes: 0

Views: 1341

Answers (1)

Shadow
Shadow

Reputation: 9427

For this example - yes.

But leading 0s like this is actually octal notation.

01 == 1. But 011 is actually 9.

Basically - you don't want to do this.

Upvotes: 6

Related Questions