Setting properties on a primitive now throws in strict mode

Published: | Categories: JavaScript

Description

Previously, setting properties on a primitive value, including String, Number, Boolean and Symbol, resulted in a no-op (did nothing). On Firefox 46 and later, such code in strict mode will throw a TypeError according to the ECMAScript 2015 (ES6) spec. See the examples below:

(function() {
  "use strict";
  (10).sub = 5; // TypeError
})();
(function() {
  "use strict";
  false.x = false; // TypeError
})();
(function() {
  "use strict";
  "test".mode = "verbose"; // TypeError
})();
(function() {
  "use strict";
  Symbol().check = true; // TypeError
})();

References