JavaScript TypeError – Property “X” is non-configurable and can’t be deleted
This JavaScript exception property is non-configurable and can’t be deleted if the user tries to delete a property, and the property is non-configurable.
Message:
TypeError: Calling delete on 'x' is not allowed in strict mode (Edge) TypeError: property "x" is non-configurable and can't be deleted. (Firefox) TypeError: Cannot delete property 'x' of #<Object> (Chrome)
Error Type:
TypeError
Cause of Error: There is an attempt to delete a property that is non-configurable.
Example 1: In this example, the delete is used to delete a non-configurable property, So the error has occurred.
Javascript
'use strict' ; let GFG_Obj = Object.freeze({ prop1: 'val1' , prop2: 123 }); delete GFG_Obj.prop2; // Error here |
Output(in console):
TypeError: Calling delete on 'prop2' is not allowed in strict mode
Example 2: In this example, the delete is used to delete PI which is a non-configurable property, So the error has occurred.
Javascript
'use strict' ; delete Math.PI; // Error here |
Output(in console):
TypeError: Calling delete on 'PI' is not allowed in strict mode
Contact Us