πŸŽ‰ We just launched our new React course! Get it with 20% off! πŸŽ‰

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.
Looking to improve your skills? Check out our interactive course to master JavaScript from start to finish.
Master JavaScript

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."

JavaScript Course Dashboard

Tired of looking for tutorials?

You are not alone. Webtips has more than 400 tutorials which would take roughly 75 hours to read.

Check out our interactive course to master JavaScript in less time.

Learn More

Recommended