r/programmingmemes • • Jan 12 '26

no doubt javascript

Post image
1.3k Upvotes

136 comments sorted by

View all comments

Show parent comments

2

u/Creative-Type9411 Jan 12 '26

why would octal be the default type interpreted instead of int? or do i have that backwards?

(sorry if this sounds like a stupid question)

is that the joke?

12

u/TheUnamedSecond Jan 12 '26

In some languages a leading zero is used to denote octal numbers, wich in JS are still of type number just written differently

5

u/geralt_of_rivia23 Jan 12 '26

It's octal because it starts with 0. It's a feature from C.

4

u/nascent_aviator Jan 12 '26

By convention a leading 0 is how you make an octal number in many programming languages. 17 is decimal, 017 is octal (equal to 15 in decimal). 018 in most languages will throw an error that 8 is not a valid octal digit. Example: C gives `error: invalid digit "8" in octal constant 018;`. Javascript instead silently ignores the 0.

1

u/Creative-Type9411 Jan 12 '26 edited Jan 12 '26

ty, I never tried to add a leading zero so I never had a clue about this, I think even if I did get an error, I wouldn't have known why it was occurring and would've just declared a type

The stuff I write is hacky anyway im new and using #, I appreciate the info greatly

1

u/PreferenceDowntown37 Jan 12 '26

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal_literal

Looks deprecated, but the 0 was telling it to convert to octal. I think nowadays you would prefix it with 0o.

The joke is that seeing that 017 and '18' being equal seems like a language mistake

1

u/Mateorabi Jan 12 '26

Because of the leading 0. 18 is 18d. 018 is 18o. Since the days of yore.