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.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
    'use strict';
    var GFG_Obj = Object.freeze({prop1: 'val1', prop2: 123});
    delete GFG_Obj.prop2;  // Error here
</script>

chevron_right


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.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
    'use strict';
    delete Math.PI;  // Error here
</script>

chevron_right


Output(in console):

TypeError: Calling delete on 'PI' is not allowed in strict mode

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.