Javascript Methods Flashcards

1
Q

What is a method?

A

a function that is an object property

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

How is a method different from any other function?

A

methods are associated with an object; functions are not

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

How do you remove the last element from an array?

A

array.pop( );

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

How do you round a number down to the nearest integer?

A

Math.floor( );

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

How do you generate a random number?

A

Math.random( );

to figure out max 0 < 1 and does not include 1

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

How do you delete an element from an array?

A

array.splice(index, # of items to delete, [item1 to be added, item2 to be added, etc])

[optional part!]

kind of like selective surgery on an array

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

How do you append an element to an array?

A

array. push( new item1, new item2, etc. )

prepend: array.unshift ( );

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

How do you break a string up into an array?

A

string.split ( pattern/delimiter );

opposite is array.join ( pattern/delimiter );

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

Do string methods change the original string? How would you check if you weren’t sure?

A

No, strings are unchangeable

can console.log it

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

Roughly how many string methods are there according to the MDN Web docs?

A

~ 50

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

Is the return value of a function or method useful in every situation?

A

no, sometimes the return value is not needed, like in a push

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

Roughly how many array methods are there according to the MDN Web docs?

A

~ 50

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

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

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

What is Array.prototype.reduce useful for?

A

take and array and condense content into a SINGLE VALUE

essentially can loop through an array and reduce to single value

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

What is Array.prototype.filter useful for?

A

creates new array with all elements that pass the test implemented by provided function

useful for accessing properties on objects

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

What is Array.prototype.map useful for?

A

create new array from calling a function for each array element