What does JSON.stringify do?

Question

In the context of this exercise, what does JSON.stringify do?

Answer

JSON.stringify is a method that converts a JavaScript object into a string. One use of the method is to store the object as a string in a database, and then convert back to an object when obtaining it.

For example,

JSON.stringify({ a: 1, b: 2 });
// "{"a": 1, "b": 2}"
12 Likes