JavaScript delete Operator

You are Here:

JavaScript delete Operator

The delete operator removes a property from an object.

On successful deletion, it will return true, else false will be returned.

The following are the key points to be noted while using delete operator.

  • If the property which you are trying to delete does not exist, delete will not have any effect and will return true.
  • Any property declared with const or let cannot be deleted from the scope within which they were defined.
  • Any property declared with var cannot be deleted from the global scope or from a function's scope.
  • Non-configurable properties such as built-in objects like Math, Array and methods like Object.defineProperty() cannot be removed.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <p id="point1"></p> <script> var x = document.getElementById("point"); var y = document.getElementById("point1"); var bike = {brand: "Honda", color: "red"}; x.innerHTML = bike.brand; delete bike.brand; y.innerHTML = bike.brand; </script> </body> </html>

Syntax

Using Dot Notation

delete object.propertyName

Using Bracket Notation

delete object["property"]

Parameter Values

ValueTypeExplanation
objectRequiredThe name of an object.
propertyNameRequiredThe property to delete.

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author