obj.toString() returns a string version of the object. For a plain object the default is "[object Object]".
You can override toString on your object or class for friendlier text. Object.prototype.toString.call(value) is also a classic way to read internal type tags like "[object Array]".
Syntax
Call obj.toString() like this. Start with this line.
JavaScript
obj.toString()
Call
What it does
obj.toString()
Returns a string; default plain object result is "[object Object]".
Object.prototype.toString.call([])
Returns "[object Array]" — useful type tagging.
String(obj)
Also ends up calling toString (or valueOf) during conversion.
No required parameters on Object.prototype.toString. Many other types override this method.
Library declarations
JavaScript
obj.toString()
JavaScript
object.toString(): string
Parameters
Parameter
Description
(none)
Object.prototype.toString takes no parameters.
Return Value
Return Value
Description
string
A string describing the object. Default for plain objects: "[object Object]".
JavaScript Examples
Default Plain Object String
See the built-in result and how string joining uses it.
JavaScript
var user = { name: "Ada" };
console.log(user.toString());
console.log("User: " + user);
console.log(String(user));