JS Flashcards

1
Q

How to you store data in localStorage?

A

localStorage.setItem(‘myCat’, ‘Tom’);

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

How to you retrieve data from localStorage?

A

localStorage.getItem(‘myCat’);

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

What data type can localStorage save in the browser?

A

only strings

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

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

A

when the document and it’s resources are about to be unloaded, or closing the browser

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

What is JSON?

A

text-based data format following JavaScript object syntax

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

What are serialization and deserialization?

A

Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network. Deserialization is the reverse process: turning a stream of bytes into an object in memory.

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

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

A

JSON.Strignify

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

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

A

JSON.Parse

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

What is the event.target?

A

target property of the Event interface is a reference to the object onto which the event was dispatched.

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

What is the affect of setting an element to display: none?

A

it makes it invisible and takes it out of document

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

What does the element.matches() method take as an argument and what does it return?

A

it takes an argument of css selector, returns a boolean, weather css selector matches the element

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

How can you retrieve the value of an element’s attribute?

A

get attribute method

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

At what steps of the solution would it be helpful to log things to the console?

A

every step

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

If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?

A

you would have to list every tab element with multiple listeners

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

If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

A

you need a list of explicit conditionals,

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

What is the event.target?

A

target property of the event interface, reference to the object which event was dispatched

17
Q

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

because of the default document flow, which is set to event bulling, so starts at the most specific elements, then less specific

18
Q

What DOM element property tells you what type of element it is?

A

event.target

19
Q

What does the element.closest() method take as its argument and what does it return?

A

the argument is a selector and it returns it’s self or nearest ancestor element

20
Q

How can you remove an element from the DOM?

A

use .remove method

21
Q

f you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?

A

you would add an event listener to the parent, using event delegation

22
Q

Does the document.createElement() method insert a new element into the page?

A

no, it just simply create the element,that’s going to be added to the dom

23
Q

How do you add an element as a child to another element?

A

append child method

24
Q

What do you pass as the arguments to the element.setAttribute() method?

A

attribute name and the value

25
Q

What steps do you need to take in order to insert a new element into the page?

A

create element, grab the spot you want to append it to, append it

26
Q

What is the textContent property of an element object for?

A

assigning text content to the new element, and also for knowing the text content in the text element

27
Q

Name two ways to set the class attribute of a DOM element.

A

assigning a new name to the class property and the other way is set attribute

28
Q

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A

repetition and make it dynamic

29
Q

What event is fired when a user places their cursor in a form control?

A

focus

30
Q

What event is fired when a user’s cursor leaves a form control?

A

blur

31
Q

What event is fired as a user changes the value of a form control?

A

input

32
Q

What event is fired when a user clicks the “submit” button within a ?

A

submit

33
Q

What does the event.preventDefault() method do?

A

if the event is not explicitly handled, its default action should be taken

34
Q

What does submitting a form without event.preventDefault() do?

A

refreshes the page and adds the data on the url

35
Q

What property of a form element object contains all of the form’s controls.

A

elements property

36
Q

What property of form a control object gets and sets its value?

A

value property