Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Why does the delete operator deletes a function constructor?

In this post, It says that the delete operator does not work on functions.

The invocation of the delete operator returns true when it emoves a property and false otherwise. it’s only effective on an object’s properties, it has no effect on variable or function names.

But consider this code:

delete Date;
new Date(); // thros an reference error

To make sure that Date is a function constructor, I wrote:

typeof Date; // "function"

This piece of code verifies that Date is a constructor, not an object. If the delete operator work on this particular type of function constructor, it should work on my constructor also. But it doesn't.

function a(){}
var b = new a();
delete a; // false

So, the delete operator did not delete my function constructor but for some reason, it deleted the Date constructor. Can someone clear this confusion of mine?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are doing this in a browser context then Date is a property on window, which is what you actually deleted. That the value of that property is a constructor/function doesn't really matter, the property is gone and most likely that was your only reference to that function.

This still works and returns a date object.

var dateFn = Date;
delete Date;
new dateFn();

Because it was only the property that was removed and not the actual function.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!