Fixing "Delete of an unqualified identifier" Errors in JS

Ferenc Almasi β€’ 2022 July 11 β€’ Read time 2 min read
  • twitter
  • facebook
JavaScript

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.

Copied to clipboard! Playground
'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

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.

Copied to clipboard! Playground
'use strict'
const cloud = {
    emoji: '☁️'
}

// βœ”οΈ cloud.emoji is now undefined
delete cloud.emoji

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:

Copied to clipboard! Playground
'use strict'

let cloud = '☁️'

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

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

  • twitter
  • facebook
JavaScript
Did you find this page helpful?
πŸ“š More Webtips
Frontend Course Dashboard
Master the Art of Frontend
  • check Access 100+ interactive lessons
  • check Unlimited access to hundreds of tutorials
  • check Prepare for technical interviews
Become a Pro

Courses

Recommended

This site uses cookies We use cookies to understand visitors and create a better experience for you. By clicking on "Accept", you accept its use. To find out more, please see our privacy policy.