Skip to content
Related Articles

Related Articles

Improve Article
JavaScript TypeError – Can’t redefine non-configurable property “x”
  • Last Updated : 13 Aug, 2020

This JavaScript exception can’t redefine non-configurable property occurs if user tries to redefine a property, but that property is non-configurable.

Message:

TypeError: Cannot modify non-writable property {x} (Edge)
TypeError: can't redefine non-configurable property "x" (Firefox)
TypeError: Cannot redefine property: "x" (Chrome)

Error Type:

TypeError

Cause of the Error: If there is an attempt to redefine a property, but that property is non-configurable.

Example 1: In this example, the ‘prop1’ is being attempted to change the value, so the error has been occurred.



HTML




<script>
var GFG_Obj = Object.create({});
Object.defineProperty(GFG_Obj, "prop1", {value: "val1"}); 
Object.defineProperty(GFG_Obj, "prop1", {value: "val2"});
</script>

Output:

TypeError: Cannot modify non-writable property 'prop1'

Example 2: In this example, the ‘prop2’ is being attempted to change the value, So the error has occurred.

HTML




<script>
var Obj = Object.create({"prop1": "val1"});
Object.defineProperty(Obj, "prop2", {value: "val21"}); 
Object.defineProperty(Obj, "prop2", {value: "val22"});
</script>

Output:

TypeError: Cannot modify non-writable property 'prop2'
My Personal Notes arrow_drop_up
Recommended Articles
Page :