Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 904 Bytes

no-const-outside-module-scope.md

File metadata and controls

35 lines (24 loc) · 904 Bytes

Only allow const at the top level of a module (no-const-outside-module-scope)

The rule enforces the use of const only as a true constant, a value that will only ever have a single value across the entire lifetime of your application.

A good, brief explanation is below:

const to express variable bindings that should ABSOLUTELY not change, not bindings that happen to not change. let express variable bindings that may or may not change.

-- Stefan Penner

Rule Details

The following patterns are good:

const FOO = 'FOO';
export const BAR = 'BAR';

The following patterns are bad:

function derp() {
  const FOO = 'FOO';
}

if (false) {
  const BLAH = 'BLAH';
}

When Not To Use It

If you want to use const anywhere in your code, then you should turn this rule off.