String Methods Flashcards

1
Q

What does String.length do?

A

Returns the length of a string (technically property)

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

What does String.slice(start, end) do?

A

Extracts a part of a string (specify where it starts and ends in the parameters) and returns it in a new string.

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

What does String.substring(start, end) do?

A

Extracts part of a string and returns it as a new string.

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

What is the difference between substring and splice?

A

If start > stop, then substring will swap those 2 arguments. With substring, if it is NaN or negative it will treat the value as 0.

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

What does String.substr(start, end) do?

A

Extracts a part of a string and returns a new string - the second parameter specifies the length of the extracted part (that is what makes it different)

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

What does String.replace(thing you want to replace, replace with)

A

Replaces a specified value with another value in a string - returns a new string

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

What are some limitations of String.replace()

A

Only returns the first match (use /g flag to replace all), does not change the string it is called on, case sensitive, (use /i to ignore the case)

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

What does String.replaceAll() do?

A

Allows you to specify a regular expression instead of a string to be replaced - if the parameter is a regular expression it

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