JSON Flashcards
What is JSON?
JS object notation
used to send data btwn computer systems
What are serialization and deserialization?
serialization: converting an Object into stream of bytes so that it can be transferred over a network or stored in a persistent storage.
deserialization: Fetch 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?
pack up and send data
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify(objectName);
must stringify to send as JSON
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse(stringName);
must parse to use in JS
How to you store data in localStorage?
localStorage.setItem( ‘key’, ‘value’ )
How to you retrieve data from localStorage?
localStorage.getItem ( ‘key’ );
What data type can localStorage save in the browser?
JSON only - string data for keys and values
When does the ‘beforeunload’ event fire on the window object?
before window, document, etc are about to be unloaded. document is visible.