I'm fairly new to javascript. I noticed that apparently when operating in "use strict" mode, you can't delete objects. I'm not a huge fan of deleting things (since, in theory, scope should take care of that anyway), but I wonder what was the motivation behind removing this feature?
Javascript – Why is delete not allowed in Javascript5 strict mode
ecmascript-5javascriptstrict-mode
Related Topic
- Javascript – the !! (not not) operator in JavaScript
- Javascript – What does “use strict” do in JavaScript, and what is the reasoning behind it
- Javascript – JSONP, and why was it created
- Javascript – Open a URL in a new tab (and not a new window)
- Javascript – Why does ++[[]][+[]]+[+[]] return the string “10”
- Javascript – Motive behind strict mode syntax error when deleting an unqualified identifier
- Javascript – Why does the JavaScript code receive a “No ‘Access-Control-Allow-Origin’ header is present on the requested resource” error, while Postman does not
Best Answer
The
delete
statement is still allowed in strict mode, but some particular uses of it are erroneous. It's only allowed for object properties, not simple names, and only for object properties that can be deleted.Thus
is fine, but
is not, and neither is
(The latter is actually a syntax-level error, while an attempt to delete an undeletable property is a runtime error.)