JSON Flashcards
What is JSON?
JavaScript Object Notation. It’s a standard text-based format for representing structured data based on JavaScript object syntax. This is commonly used for transmitting data in web applications.
What are serialization and deserialization?
Serialization is the process of converting an object in memory into a byte stream so that it can be stored on disk or transferred over the network. Deserialization is the inverse process of converting a stream of bytes into an object in memory.
Why are serialization and deserialization useful?
To save the state of an object in order to be able to recreate it when needed.
How do you serialize a data structure into a JSON string using JavaScript?
Using the JSON.stringify() method.
How do you deserialize a JSON string into a data structure using JavaScript?
Using the JSON.parse() method.
How do you store data in localStorage?
Using the setItem() method.
How do you retrieve data from localStorage?
Using the getItem() method.
What data type can localStorage save in the browser?
Only strings.
When does the ‘beforeunload’ event fire on the window object?
The event is fired when the window, the document, and its resources are about to be unloaded, like refresh or close the window.