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

93
Views
Deleting Objects in JavaScript. I'm a bit confused with JavaScript's delete operator

I'm a bit confused with JavaScript's delete operator.I am begginer in JS. Take the following piece of code:

function removeName (person){

   let user = {
       name : "name",
       surname: "surname"
   } ;
   console.log(delete user.name);

}
let x;
x = removeName();
console.log(x);

After this piece of code has been executed,I take as output true and undefinied, I take undefinied because I find it difficult to do object in function but true why? Please I am a beginner, so I think my code is miserable.

This confuses me, because I expected that writing delete user.name would delete it and not just throw a true one.

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

0

Delete returns true. However you return nothing, so the function retuns undefined.

let user = {
  name : "name",
  surname: "surname"
};
delete user.name
console.log(user);

about 4 years ago · Juan Pablo Isaza Report

0

Looking at the definition of removeName, you're expected to send a person. You're currently not doing that, and you're placing the person inside the function too, and that would just end up scoping the person to this object.

So based on that info, this is how I assume you meant to write the code.

let user = {
  name : "name",
  surname: "surname"
};

function removeName (person){
   delete person.name;
}

removeName(user);
console.log(user);

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!