js Flashcards

1
Q

how to check a click is touch or mouse click

A

onclick => (e) => e.type === “touchdown”

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

how to get the x position in touch

A

(e) => e.touches[0].clientX

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

how to get the node of clicked element

A

(e) => element = e.target

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

how to style an element

A

element.style.nameOfStyle = “string”

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

what it selects ? document.getElementsByClassName(“item”)

A

return an array

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

how to get the class name of a fired event from event Listener

A

e.target.className

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

target vs currentTarget

A

Basically, events bubble by default so the difference between the two is:

target is the element that triggered the event (e.g., the user clicked on)
currentTarget is the element that the event listener is attached to.

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

how to transfer the id via in an event

A

in sender
event.dataTransfer.setData( ‘text/plain’, event.target.id)
in the receiver
event.dataTransfer.getData(“text”)

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

200 < x < 500 ?

A

return x >= min && x <= max

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

how to map array of the nodelist

A

Array.from(nodelist).map

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

we have a random number of items in a container, we need to define an event listener on them, how we can get the active item

A

if ( e.target !== e.currentTarget ) // make sure that the item is not container itself
actvieItem = e.target

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

append vs appendChild

A

.append accepts Node objects and DOMStrings while .appendChild accepts only Node objects
.append does not have a return value while .appendChild returns the appended Node object
.append allows you to add multiple items while appendChild allows only a single item

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

Object.assign(target, …sources)

A

Object.assign() is used for cloning an object.

Object.assign() is used to merge object with same properties.

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