JSON Flashcards
What is JSON?
JSON is a text-based data format following JavaScript object syntax. JSON exists as a string which is useful when you want to transmit data across a network
What are serialization and deserialization?
Serialization is a process of converting an Object into stream of bytes so that it can be transferred over a network or stored in a persistent storage.
Deserialization is the exact opposite - It fetches a stream of bytes from network or persistence storage and convert it back to the Object with the same state
Why are serialization and deserialization useful?
It makes it much easier to send data across networks and between devices
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse()
How do you store data in localStorage?
localStorage.setItem(key, value)
How do you retrieve data from localStorage?
localStorage.getItem(key)
What data type can localStorage save in the browser?
JSON string
When does the ‘beforeunload’ event fire on the window object?
The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point