json Flashcards

1
Q

What is JSON?

A

data interchange format used to send and store information in computer systems; text-based data format; exists as a string and needs to be converted to a native js object when you want to access the data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are serialization and deserialization?

A

serialization: converting a native object to a string so it can be transmitted across the network
deserialization: converting a string to a native object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why are serialization and deserialization useful?

A

transmit data across a network

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify: converts a JavaScript object or value to a JSON string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.parse: parses a JSON string, constructing the JavaScript value or object described by the string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

json and strings

A

JSON requires double quotes to be used around strings and property names. Single quotes are not valid other than surrounding the entire JSON string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

simplest json

A

a single string or number would be valid JSON; can actually take the form of any data type that is valid for inclusion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to you store data in localStorage?

A

first, use the stringify method of the json object to turn the data (the argument of the method) to a string

then use the

set item method of the local storage object with two arguments, key name and key value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to you retrieve data from localStorage?

A

get item method of the local storage object with the kay name as the argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What data type can localStorage save in the browser?

A

strings; not objects nor arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When does the ‘beforeunload’ event fire on the window object?

A

when the window, the document and its resources are about to be unloaded; a confirmation dialog asking the user if they really want to leave the page; to show the confirmation dialog an event handler should call preventDefault() on the event

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

setItem

A

arg:
- keyname: A DOMString containing the name of the key you want to create/update.
- key value: A DOMString containing the value you want to give the key you are creating/updating.
return: undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

getItem

A

arg: A DOMString containing the name of the key you want to retrieve the value of
return: A DOMString containing the value of the key. If the key does not exist, null is returned

use a if statement after get

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Window.localStorage

A

The localStorage read-only property of the window interface allows you to access a Storage object for the Document’s origin; the stored data is saved across browser sessions; value: a Storage object which can be used to access the current origin’s local storage space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

how to clear local storage?

A

use the delete method, i.e., localStorage.clear();

set the data to empty set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly