JSON Flashcards
What is JSON?
JSON (JavaScript Object Notation) is a text-based data format that follows JavaScript object syntax. It represents structured data as a string.
What are serialization and deserialization?
Serialization converts an object/array to a stream of bytes to store or send over a network.
Deserialization converts a stream of bytes to an object/array that can be used in a program.
Why are serialization and deserialization useful?
It allows objects to be saved, transferred, and recreated.
How do you serialize a data structure into a JSON string using JavaScript?
The .stringify() method on the JSON object.
How do you de-serialize a JSON string into a data structure using JavaScript?
The .parse() method of the JSON object.
How do you store data in localStorage?
By calling the .setItem() method of the localStorage object with two arguments: a string for the key and a JSON string for the value.
How do you retrieve data from localStorage?
By calling the .getItem() method of the localStorage property with one argument: the string of the key.
What data type can localStorage save in the browser?
The string data type.
When does the ‘beforeunload’ event fire on the window object?
Before the tab is closed or refreshed. Anything that would cause the application to reload or close.