JavaScript SyntaxError – Applying the ‘delete’ operator to an unqualified name is deprecated
This JavaScript exception applying the ‘delete’ operator to an unqualified name is deprecated works in strict-mode and it occurs if variables are tried to be deleted with the delete operator.
Message:
SyntaxError: Calling delete on expression not allowed in strict mode (Edge) SyntaxError: applying the 'delete' operator to an unqualified name is deprecated (Firefox) SyntaxError: Delete of an unqualified identifier in strict mode. (Chrome)
Error Type:
SyntaxError
Cause of Error: In strict mode, trying to delete a variable will throw an error and is not permitted. Normal variables in JavaScript can’t be deleted with help of the delete operator.
Example 1:
HTML
<!DOCTYPE html> < html > < head > < title >Syntax Error</ title > </ head > < body > < script > 'use strict'; var GFG ="This is GeeksforGeeks"; document.write(GFG); GFG = null; </ script > </ body > </ html > |
Output:
This is GeeksforGeeks
Example 2: In this example, delete operator is used which causes the error.
HTML
<!DOCTYPE html> < html > < head > < title >Syntax Error</ title > </ head > < body > < script > 'use strict'; var GFG ="This is GeeksForGeeks"; document.write(GFG); delete GFG; </ script > </ body > </ html > |
Output(in console):
SyntaxError: Delete of an unqualified identifier in strict mode.