Decision Use JavaScript strict mode

accepted

Opt in to settings that raise errors for problematic code.

Decision

Use JavaScript's strict mode within all top-level functions (nested functions will inherit strict mode).

If the project only includes non-vendor code in a bundle, strict mode can be declared once at the top of the bundle file, instead of per function. When in doubt, declare strict mode per function.

If using ES modules, strict mode is implied, and should not be declared.

Use ESLint to detect non-strict files

Use ESLint's strict rule to detect and enforce strict mode, if you are already using ESLint in your project.

Add strict to the rules section of your ESLint configuration file.

strict: [
  'error',
  'safe'
]

Some popular rule sets, like airbnb-base, may not include this rule. Adding it to the eslint configuration file will ensure it is applied.

Consequences

JavaScript errors will be more noticeable, leading to better code quality.