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

309
Views
What does it mean that `toString` gets “ignored” if it returns a non-primitive?

The MDN documentation on Object.prototype.toString says that when toString gets overriden, it should only return a primitive value:

The toString() function you create must return a primitive, otherwise it will be ignored.

However, in the following example we return an object inside of toString and it returns the object normally:

const ob2 = {
    val1: 100,
    val2: 200,
    toString: function() {
      return {
        veh: "meh"
      }; // Object.
    }
  };

console.log(ob2.toString());

Output:

{ veh: "meh" }

So the toString method returns the object normally. What is up with the misinformation?

over 4 years ago · Santiago Trujillo
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!