Fixing "Delete of an unqualified identifier" Errors in JS

Ferenc Almasi β€’ 2022 July 11 β€’ πŸ“– 2 min read

TheΒ "Uncaught SyntaxError: Delete of an unqualified identifier in strict mode." error occurs in JavaScript, whenever you try to use the delete keyword on a variable in strict mode. In order to fix the error, avoid using the delete keyword on variables.

'use strict'

const cloud = '☁️'

// ❌ This will throw "Uncaught SyntaxError: Delete of an unqualified identifier in strict mode."
delete cloud
Trying to free up a variable by using the delete keyword in strict mode
Copied to clipboard!

Strict mode in JavaScript eliminates silent errors, prohibits certain syntax, and fixes mistakes that make it difficult for JS engines to perform optimizations.

In the above code example, we are using strict mode, and we try to delete a variable using the delete keyword. In non-strict mode, this operation will only return false. But in strict mode, we will get the following error:

Uncaught SyntaxError: Delete of an unqualified identifier in strict mode.

Why is this error happening?

The delete operator in JavaScript cannot be used on variables. It is not allowed in strict mode, therefore you will get the above error. The delete operator can only be used on the properties of an object. Object properties are "qualified identifiers", therefore if you use the delete operator on them, you won't get an error.

'use strict'
const cloud = {
    emoji: '☁️'

// βœ”οΈ cloud.emoji is now undefined
delete cloud.emoji
Copied to clipboard!

Moreover, the delete operator cannot be used to free up memory. In case you would like to free up the value of a variable, you can simply assign it to null:

'use strict'

let cloud = '☁️'

// βœ”οΈ Correct way to free up a variable
cloud = null
Copied to clipboard!

Notice that the variable has been changed to let. You cannot reassign values to a const, otherwise, you will get another error: "Uncaught TypeError: Assignment to constant variable."

Remove ads Remove ads

πŸ“š Get access to exclusive content

Want to get access to exclusive content? Support webtips with the price of a coffee to get access to tips, checklists, cheatsheets, and much more. β˜•

Get access Support us
Remove ads
Remove ads
Remove ads
πŸŽ‰ Thank you for subscribing to our newsletter. x