js basics Flashcards

1
Q

slice

A

Returns a shallow copy of a portion of an array from start to end (the end is not included)

[].slice(start, end);

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

splice

A

method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place

[].splice(start, deleteCount, item1, item2, itemN)

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

concat

A

this method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array

array1.concat(array2);

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

reduce

A

it runs a callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value

array1.reduce((previousValue, currentValue) => previousValue+currentValue, initialValue);

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

filter

A

creates a new array of all elements that pass the qualifying function argument

[].filter(x => x.length > 6);

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

map

A

creates a new array of the elements created by calling the provided function on each element of an array
[].map(x => x * 2);

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

what does .?? do

A

a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand

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

what is this called .??

A

Nullish coalescing operator

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

what does .? do?

A

enables you to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid

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

get

A

used to get a resource from a server

If you perform a GET request, the server looks for the data you requested and sends it back to you. In other words, a GET request performs a READ operation.

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

post

A

used to create a new resource on a server

If you perform a POST request, the server creates a new entry in the database and tells you whether the creation is successful. In other words, a POST request performs an CREATE operation.

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

what is .?

A

a optional chaining operator

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

PUT

A

used to update a resource on a server. If you perform a PUT or PATCH request, the server updates an entry in the database and tells you whether the update is successful

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

PATCH

A

used to update a resource on a server. If you perform a PUT or PATCH request, the server updates an entry in the database and tells you whether the update is successful

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

DELETE

A

used to delete a resource from a server. If you perform a DELETE request, the server deletes an entry in the database and tells you whether the deletion is successful

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

shift

A

remove from the begining of an array

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

push

A

add an item to the end of the array and returns that element

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

pop

A

remove the last item from an array and returns that element

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

shift

A

removes the first element from an array and returns that removed element

20
Q

unshift

A

adds one or more elements to the beginning of an array and returns the new length of the array

[].unshift(2,3);

21
Q

throttle

A

enforces a maximum number of times a function can be called overtime.

22
Q

bind

A

returns a function bound to the specified context that can be executed later on

23
Q

apply

A

invokes a function with a specified context and passes arguments as an array

24
Q

call

A

invokes a function with a specified context and passes arguments as extra arguments

var obj = { num: 2 };
function add(a){
  return this.num + a;
}
add.call(obj, 3);
25
Q

debounce

A

enforces that a function not be called again until a certain amount of time has passed without it being called

26
Q

.find

A

a method returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned

array1.find(element => element > 10);

27
Q

.some

A

a method tests whether at least one element in the array passes the test implemented by the provided function. It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false

array.some((i) => I % 2 === 0)

28
Q

.every

A

a method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
[12, 5, 8, 130, 44].every((i) => i > 10)

29
Q

.includes

A

method determines whether an array includes a certain value among its entries It returns a Boolean value.

pets.includes(‘cat’)

30
Q

what is the best way to get the parent el?

A

el.parentNode

31
Q

list the 3 best ways to get an elements children

A

1) children -> gets all the child nodes
2) firstElementChild -> gets the first child element
3) lastElementChild -> last child element

32
Q

what is the difference between childNodes, firstChild, lastChild and children, lastChildElement, and firstChildElement?

A

the former will traverse all nodes including text nodes and other types well the later will traverse only the nodes

33
Q

how can we iterate through all the children nodes?

A

for (let element of ul.children) {
element.style.background = ‘yellow’;
}

34
Q

what is the difference between nextElementSibling, previousElementSibling and nextSibling, previousSibling

A

both sets will get the siblings but the former gets only the element nodes and the latter gets all nodes including text nodes

35
Q

how do we get the next sibling node of an element?

A

el.nextElementSibling

36
Q

how do we get the previous sibling node of and element?

A

el.previousElementSibling

37
Q

how can you use class based inheritence in es6

A

class Child extends Base {.. }

38
Q

how can we pass arguments to setTimeouts execution function

A

setTimeout(func, delay, arg1, arg2)

39
Q

write a selector to get a data attribute

A

document.querySelector(‘[data-component=”dropdown”]’)

or

document.querySelectorAll(‘[data-dropdown]’);

40
Q

what can be done to prevent parser blocking due to scripts?

A

add async to the script

41
Q

what is the difference between event.currentTarget and event.target

A
  • event.target is a reference to the object that dispatched the event
  • event.currentTarget always refers to the element to which the event listener has been attached
42
Q

example of event delegation

A
function toggleDone (event) {
  if (!event.target.matches(‘input’)) return
  console.log(event.target)
  //We now have the correct input - we can manipulate the node here
}

characterList.addEventListener(‘click’, toggleDone)

43
Q

.matches

A

checks to see if the element would be selected by the provided selector string

event. target.matches(‘input’)
event. target.matches(‘.my-class’)

44
Q

what are the two ContentTypes for REST?

A
Content-Type: text/html
Content-Type: multipart/form-data
Content-Type: application/json
Content-Type: text/plain
Content-Type: application/x-www-form-urlencoded
45
Q

application/x-www-form-urlencoded vs multipart/form-data ?

A

multipart/form-data is better for large forms or binary data

46
Q

how can we replace all none alphanumaric chars in a string?

A

string.replace(/[^\w]/g, “”).toLowerCase()

47
Q

how can you determine how many arguments a function requires?

A

fn.length

see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length