What is the purpose of JSON.stringify() in JavaScript?
a) To convert a JavaScript object into a JSON string
b) To convert a JSON string into a JavaScript object
c) To sort the properties of a JavaScript object
d) To clone a JavaScript object
Answer:
a) To convert a JavaScript object into a JSON string
Explanation:
The JSON.stringify()
method converts a JavaScript object or value into a JSON string. This is useful for storing or sending data in a text format, such as transmitting data between a server and web application.