In strict mode, read-only variables cannot be assigned

  • STRICT_MODE_ASSIGN_TO_READONLY_VAR
  • Error
  • High
  • No tags

This rule applies when a value is assigned to read-only variables in strict mode.

The read-only variables are as follows:

  1. import bindings
  2. Predefined global variables such as undefined, NaN, Infinity

Any assignment to the above variables that silently fails in normal code will throw TypeError exception in strict mode.

Note: Applied for module code without "use strict" directive since module code is always strict mode code.

Noncompliant Code Example

// Example 1
import {A} from 'a';
A = 1; // STRICT_MODE_ASSIGN_TO_READONLY_VAR alarm because it is module code

// Example 2
'use strict';
undefined = 1; // STRICT_MODE_ASSIGN_TO_READONLY_VAR alarm
NaN = 2; // STRICT_MODE_ASSIGN_TO_READONLY_VAR alarm
Infinity = 3; // STRICT_MODE_ASSIGN_TO_READONLY_VAR alarm

Compliant Code Example

Version

This rule was introduced in DeepScan 1.0.0-alpha.

See