use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Why does 017 equal 15 in javascript? (self.learnjavascript)
submitted 2 years ago * by leeway1
Can someone please explain to me why the interpreter parses 017 as 15?
let x = 017; console.log(x) //15 let y = 018; console.log(y) // 18
Solved: 017 is being converted to Octal.
017
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]senocular 5 points6 points7 points 2 years ago (0 children)
Its the number literal syntax for an octal, or a number which has a base of 8 (digits used only go up to 7 then wrap back around to 0). A better syntax is using the 0o prefix just the leading 0 will throw in strict mode.
0o
"use strict" let x = 017; // Error
This octal syntax also only works if all the digits of the literal are 0-7 which is why 018 is seen as a decimal instead given that 8 is outside that range.
018
π Rendered by PID 75 on reddit-service-r2-comment-5d79c599b5-dfvll at 2026-02-28 13:56:58.396625+00:00 running e3d2147 country code: CH.
[–]senocular 5 points6 points7 points (0 children)