toString()  Object  instance method getterS2C Home  « Globals « Object « toString()


Returns a string of the specified object.

  • Automatically invoked when an object is called and a string is expected or when viewing the object as a string.
  • The Object.toString() method is inherited by all Object descendants.
  • Unless overridden by a custom object toString() returns [object Object].


Signature Description
anObject.toString()Returns a string of the specified object.




The code below creates an object and displays it.

// Create an object.
anObject = new Object();
alert(anObject.toString() + ' anObject is an Object instance.');

Press the button below to action the above code:

Related Tutorials

JavaScript Basic Tutorials - Lesson 7 - Objects

go to home page Homepage go to top of page Top