Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1064886 of TypeError: property "x" is non-configurable and can't be deleted

  • Revision slug: Web/JavaScript/Reference/Errors/Cant_delete
  • Revision title: TypeError: property "x" is non-configurable and can't be deleted
  • Revision id: 1064886
  • Created:
  • Creator: fscholz
  • Is current revision? Yes
  • Comment new page

Revision Content

{{jsSidebar("Errors")}}

Message

TypeError: property "x" is non-configurable and can't be deleted. (Firefox)
TypeError: Cannot delete property 'x' of #<Object> (Chrome)

Error type

{{jsxref("TypeError")}} in strict mode only.

What went wrong?

It was attempted to delete a property, but that property is non-configurable. The configurable attribute controls whether the property can be deleted from the object and whether its attributes (other than writable) can be changed.

This error happens only in strict mode code. In non-strict code, the operation returns false.

Examples

Non-configurable properties are not super common, but they can be created using {{jsxref("Object.defineProperty()")}} or {{jsxref("Object.freeze()")}}.

"use strict";
var obj = Object.freeze({name: "Elsa", score: 157});
delete obj.score;  // TypeError

"use strict";
var obj = {};
Object.defineProperty(obj, "foo", {value: 2, configurable: false});
delete obj.foo;  // TypeError

"use strict";
var frozenArray = Object.freeze([0, 1, 2]);
frozenArray.pop();  // TypeError

There are also a few non-configurable properties built into JavaScript. Maybe you tried to delete a mathematical constant.

"use strict";
delete Math.PI;  // TypeError

See also

  • delete operator
  • {{jsxref("Object.defineProperty()")}}
  • {{jsxref("Object.freeze()")}}

Revision Source

<div>{{jsSidebar("Errors")}}</div>

<h2 id="Message">Message</h2>

<pre class="syntaxbox">
TypeError: property "x" is non-configurable and can't be deleted. (Firefox)
TypeError: Cannot delete property 'x' of #&lt;Object&gt; (Chrome)
</pre>

<h2 id="Error_type">Error type</h2>

<p>{{jsxref("TypeError")}} in strict mode only.</p>

<h2 id="What_went_wrong">What went wrong?</h2>

<p>It was attempted to delete a property, but that property is <a href="/en-US/docs/Web/JavaScript/Data_structures#Properties">non-configurable</a>. The <code>configurable</code> attribute controls whether the property can be deleted from the object and whether its attributes (other than <code>writable</code>) can be changed.</p>

<p>This error happens only in <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode code</a>. In non-strict code, the operation returns <code>false</code>.</p>

<h2 id="Examples">Examples</h2>

<p>Non-configurable properties are not super common, but they can be created using {{jsxref("Object.defineProperty()")}} or {{jsxref("Object.freeze()")}}.</p>

<pre class="brush: js example-bad">
"use strict";
var obj = Object.freeze({name: "Elsa", score: 157});
delete obj.score;  // TypeError

"use strict";
var obj = {};
Object.defineProperty(obj, "foo", {value: 2, configurable: false});
delete obj.foo;  // TypeError

"use strict";
var frozenArray = Object.freeze([0, 1, 2]);
frozenArray.pop();  // TypeError
</pre>

<p>There are also a few non-configurable properties built into JavaScript. Maybe you tried to delete a mathematical constant.</p>

<pre class="brush: js example-bad">
"use strict";
delete Math.PI;  // TypeError</pre>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/delete">delete operator</a></li>
 <li>{{jsxref("Object.defineProperty()")}}</li>
 <li>{{jsxref("Object.freeze()")}}</li>
</ul>
Revert to this revision