Skip to content

octalNumbers

Reports using legacy octal numeric literals.

✅ This rule is included in the ts untyped preset.

Legacy octal numeric literals (e.g., 077, 0123) are a deprecated feature in JavaScript that can lead to confusion and errors. They are forbidden in strict mode and are less readable than their modern alternatives. The explicit octal syntax 0o (e.g., 0o77) introduced in ES6 is clearer and works in both strict and non-strict modes. The digit 0 by itself is allowed as it represents zero, not an octal literal.

This rule reports on numeric literals with a preceding 0.

const permissions = 0755; // Evaluates to 493, not 755!
const value = 077; // Evaluates to 63, not 77!
const numbers = [01, 02, 03, 04, 05, 06, 07];

This rule is not configurable.

If you need to maintain compatibility with very old JavaScript engines that don’t support the explicit octal syntax (ES6+), you might choose to disable this rule. However, this is extremely rare in modern development, as ES6 has been widely supported since 2015.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.