Javascript Object toString()

The JavaScript Object toString() method returns the object as a string.

The syntax of the toString() method is:


Here, obj is an object.

toString() Parameters

The toString() method does not take any parameters.

Return value from toString()

  • Returns a string representing the object.

Note: Every object descended from Object inherits toString() and if not overridden, it returns "[object <type>]".

Example: Using toString()

// built-in objects
let num = 10;
// number takes in optional radix argument (numeral base)
console.log(num.toString(2)); // "1010" in binary

console.log(new Date().toString()); // Thu Aug 06 2020 12:08:44 GMT+0545 (Nepal Time)

// overriding default toString(), custom object
function Dog(name, breed, sex) { = name;
  this.breed = breed; = sex;

dog1 = new Dog("Daniel", "bulldog", "male");
console.log(dog1.toString()); // [object Object]

Dog.prototype.toString = function dogToString() {
  return `${} is a ${} ${this.breed}.`;

console.log(dog1.toString()); // Daniel is a male bulldog.


Thu Aug 06 2020 12:08:44 GMT+0545 (Nepal Time)
[object Object]
Daniel is a male bulldog.

Recommended Reading: JavaScript Object valueOf()

Did you find this article helpful?