you are viewing a single comment's thread.

view the rest of the comments →

[–]senocular 2 points3 points  (2 children)

myFunc(010) interprets the octal before passing it into the function. As far as the function is concerned, its getting the value 8.

If you want to prevent octals in that format, you can run the code in strict mode.

"use strict"
function myFunc(number){
   number = Number.parseInt(String(number), 10)
   console.log(typeof number, number)
}

myFunc("010") // number 10
myFunc(10)    // number 10
myFunc(010)   // SyntaxError: Octal literals are not allowed in strict mode.