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

165
Views
Changing how an object/function is represented in a console.log statement

I am trying to customize how an instance is printed in a console.log statement by default:

function Vehicle(x, y, z) {
    this.x = x;
    this.y = y;
    this.z = z;
    this.speed = 0;
    this.engineOn = false;
}

Vehicle.prototype.valueOf = function() {
    return 'print this';
}

let v = new Vehicle(1,2,3);
console.log(v);

It seems there is a valueOf and a toString function, but neither of those seem to change the value. How would I properly change the default format when it's cast to a string in the console.log statement?

about 4 years ago · Juan Pablo Isaza
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!