Assignment should not be made to property of primitive value

  • ASSIGN_TO_PROPERTY_OF_PRIMITIVE
  • Error
  • High, Medium
  • No tags

This rule applies when assignment is made to property of primitive value.

In such a case, an exception is thrown in strict mode. In non-strict mode, assignment is ignored unlike the intention of a programmer.

Noncompliant Code Example

View with compliant examples side by side
function h() {
    'use strict';
    var a = 'str1';
    a.prop = 42; // ASSIGN_TO_PROPERTY_OF_PRIMITIVE alarm because 'a' is a primitive string value.
}

Compliant Code Example

View with noncompliant examples side by side
function h() {
    'use strict';
    var a = new String('str1');
    a.prop = 42;
}

Version

This rule was introduced in DeepScan 1.0.0-alpha.

Was this documentation helpful?