Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:25:44+00:00 2026-06-03T00:25:44+00:00

The delete operator removes a property from an object. If I set a property

  • 0

The delete operator removes a property from an object. If I set a property on window, I can delete it:

window.myProp = 10;
delete window.myProp;

As the article I so often refer others to when it comes to the behaviour of the delete operator states, this is because property assignment does not set the DontDelete attribute (as opposed to variable declaration, which does).

That article also states the following (emphasis added):

Note that it is during property creation that attributes are
determined (i.e. none are set). Later assignments don’t modify
attributes of existing property
. It’s important to understand this
distinction.

Bearing that in mind, why can I override an existing property of window, alert, and then delete it to return to the original value? Am I missing something obvious? I rarely use the delete operator so that may well be the case.

For example:

window.alert = function() {};
alert("Hi!"); //Nothing happens

delete window.alert;
alert("Hello?"); //Alerts 'Hello?'

Here’s a fiddle to demonstrate that (only tested in Chome, pretty sure IE will not behave this way but don’t have access to anything but Chrome right now).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:25:46+00:00Added an answer on June 3, 2026 at 12:25 am

    In Chrome, the window.alert function is part of the prototype of the DOMWindow class, it’s not a property of window itself.

    Hence when you overwrite window.alert you’re adding a new property to window, but the version in the prototype continues to exist, but is hidden.

    When you delete window.alert the function in the prototype is re-exposed.

    Here’s some console output showing that the function is in the prototype:

    > window.constructor.prototype
    DOMWindow
    
    > window.constructor.prototype.alert
    function alert() { [native code] }
    

    Firefox behaves similarly, albeit with different class names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

delete from a A where a.ID = 132. The table A contains around 5000
I delete my java program from java project in eclipse. The extension was .java
I am trying to delete an old user from our perforce installation. A previous
How can I easily delete duplicates in a linked list in java?
The behaviour of the delete operator seems very complicated and there are many misunderstandings
Is this the right way to use delete[] operator? int* a=new int[size]; delete[] a;
When array is created using 'new' and deleted using 'delete' operator, delete knows the
In C++, I understand that the delete operator, when used with an array, 'destroys'
I enjoy using the operators new and delete in C++ a lot but often
Why does delete operator return true if I try to delete non existing indexed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.