What is the delete Operator in JavaScript?

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Overview

JavaScript developers often wonder what the delete operator even is. What is it used for? Why do we use JavaScript's delete operator? The delete operator is one of the most underutilized JavaScript operators and that's what we're going to fix right now.

The javascript delete operator is used to remove an element from an array, objects, and properties from an object. It's important to note that the javascript delete operator is not a method; it's a statement.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax

  • Syntax to delete an object.
  • Syntax to delete the property of an object.
  • Syntax to delete element from an array.

Description

After removing the property from the object or array element, the javascript delete operator returns true. Even if no property or index could be found in the object or array, it still returns true. Only when you attempt to delete variables and functions does it return false.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Non-configurable Properties

When you set configurable as false for a property, the delete operator returns false.

Strict Vs. Non-strict Mode

strict mode is used to write secure JavaScript. Deleting a property in strict mode will result in an error because the delete operator is prone to errors.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Can We Delete Variables in Javascript?

No, is the response. The javascript delete operator does not allow us to delete variables because they are not configurable like objects. The remove operator will return false if you do that.

Examples

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Delete and the Prototype Chain

Only the object's own properties are deleted using the delete operator. The properties of an object's prototype are unaffected. Deleting a property that is not owned by the object also has no effect but does return true.

Example:

Deleting Array Elements

Same as object properties, we can also delete elements of an array with the javascript delete operator. It will return true even if the index is not found.

Browser Compatibility

The javascript delete operator is supported by the following popular browsers.

BrowserFull support
ChromeYes
EdgeYes
FirefoxYes
OperaYes
SafariYes
Samsung InternetYes
Android WebviewYes
DenoYes
Node.jsYes

Conclusion

  • The javascript delete operator can be really useful when you want to remove an object, the property of an object, or an element from a JavaScript array.
  • delete is not a method but a statement.
  • However, there are some things that you need to be aware of so that you don't cause any bugs by using them incorrectly.
  • This article should have cleared up some of the mystery surrounding this operator and how it works in JavaScript.