Answer the question
In order to leave comments, you need to log in
Why does the console return a number in octal when writing a number with a leading zero?
Why does the console return a number in octal when writing a number with a leading zero?
I understand that by putting 0 in front of the number, the browser starts to perceive the number not as decimal but as octal, but why exactly 8, and not binary, for example?
Answer the question
In order to leave comments, you need to log in
Yes, you understood everything correctly, use predicates (0b - binary, 0o - octal, 0x - hexadecimal),
in strict mode (starting from ES5) it is generally forbidden to use an octal literal without a predicate:
function foo() {
"use strict";
0321;
}
//Uncaught SyntaxError: Octal literals are not allowed in strict mode.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question