Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Sorry for this huge lack of knowledge, but, Can someone explain me what is happening? Why does it says 511 instead of 777?
-
firusvg13739y@mikessoldier Leading 0 denotes that number is in octal (thus base 8) representation. ECMA 5th edition changed this (so leading zero doesn't denote octal but "regular" integer in base 10). /cc @ukabthebest -
@mikessoldier He is using the octal system (base 8) by adding a 0 to the front. Octal only accepts numbers 0 to 7(afaik), so 777 is correctly put out as 511, but 888 is not an actual octal number, so javascript does its thing and seems to read it as decimal (base 10).
@firusvg damn, i was too slow :P -
Adding a 0 in front turns it into an octal. 777 in base 8 is 511. 888 is an invalid base 8 number, therefore the interpreter cuts off the first 0 and keeps it in base 10.
-
Thanks for explaining everyone!
Now the question is... Does anyone know why this exists within Javascript? Not sure about you, but I don't convert things to octal... Ever. -
mt3o18769y@tylerleonhardt you don't, but this doesn't mean no one else doesn't. Octal base is useful as a part of byte. There are use cases you need to operate on bitmasks, having a type for this is handy. -
@abchin that was using the Node.js REPL that's built in to Node.
The terminal was in iterm on a Mac but you can get to this REPL by installing Node and typing node in your terminal of choice. -
abchin49y@tylerleonhardt thanks a lot, your mention of the REPL helps me a lot. I would not struggle to debug front end or back end code any longer.
-
@abchin between that and the console in your browser of choice are the best options for interacting with js quickly and simply
Related Rants

What only relying on JavaScript for HTML form input validation looks like
Found something true as 1 == 1
🙃 Javascript is beautiful 🙃
undefined
node
nodejs
wat
octal
js
javascript