JavaScript Program to Convert Objects to Strings

To understand this example, you should have the knowledge of the following JavaScript programming topics:


Example 1: Convert Object to String Using JSON.stringify()

Output

{"name":"Jack","age":27}
string

In the above example, the JSON.stringify() method is used to convert an object to a string.

The typeof operator gives the data type of the result variable.


Example 2: Convert Object to String Using String()

Output

[object Object]
Jack
string

In the above example, the String() function converts the value of an object to a string.

When using the String() function on an Object, the converted result will give [object Object].

The typeof operator gives the data type of the result variable.