JavaScript delete

Beginner
5 min read
Updated: Nov 2026
3 examples

Definition and Usage

delete obj.key removes an own property when it is configurable. It returns true when the property is gone (or never existed). It does not delete variables declared with let/const/var.

JavaScript Syntax

JavaScript
const user = { name: "Ada", age: 36 };
delete user.age;
console.log(user.age);
console.log("age" in user);
Try it Editor

How It Works

  1. Property removed. age is gone.
  2. in is false. Key no longer exists.

Examples

Example 1 — delete on arrays

Leaves a hole; prefer splice.

JavaScript
const a = [1, 2, 3];
delete a[1];
console.log(a.length, a[1]);
Try it Editor

How It Works

  1. length stays 3.
  2. Index 1 is empty.

Example 2 — Cannot delete bindings

let/const/var are not removable.

JavaScript
let x = 1;
console.log(delete x);
Try it Editor

How It Works

  1. In strict mode this throws; sloppy mode returns false.

Example 3 — Non-configurable

Frozen props resist delete.

JavaScript
const o = Object.freeze({ a: 1 });
console.log(delete o.a);
Try it Editor

How It Works

  1. freeze makes props non-configurable.

Frequently Asked Questions

It removes the property. Garbage collection may reclaim data later if nothing else references it.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful