JS String Flashcards

1
Q

How can you access a character in a string?

A

A) ‘dog’.charAt(1) // “o”

B) ‘dog’[2] // “g”

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

How can primitive strings use methods of the object String without the ‘new’ keyword?

A

JavaScript will automatically wrap the string primitive and call the method or perform the property lookup on the wrapper object instead.

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

\0

A

Escape sequence null character (U+0000 NULL)

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

' " \

A

Escape sequences
single quote (U+0027 APOSTROPHE)
double quote (U+0022 QUOTATION MARK)\
backslash (U+005C REVERSE SOLIDUS)

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

\n \r \b

A

Escape sequences
newline (U+000A LINE FEED; LF)
carriage return (U+000D CARRIAGE RETURN; CR)
backspace (U+0008 BACKSPACE)

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

\v \t \f

A

Escape sequences
backslash vertical tab (U+000B LINE TABULATION)
tab (U+0009 CHARACTER TABULATION)
form feed (U+000C FORM FEED)

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

\uXXXX

A

escape sequence
Unicode code point between U+0000 and U+FFFF
(the Unicode Basic Multilingual Plane)

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

String.prototype.length

A

a read only property, returns the length of the string

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

String.prototype.charAt(index)

String.prototype.charCodeAt(index)

String.prototype.indexOf(searchValue [, fromIndex])

String.prototype.lastIndexOf(searchValue [, fromIndex])

A

Returns the character (exactly one UTF-16 code unit) at the specified index.

Returns a number that is the UTF-16 code unit value at the given index.

Returns the index within the calling String object of the first occurrence of searchValue, or -1 if not found.

Returns the index within the calling String object of the last occurrence of searchValue, or -1 if not found.

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

String.prototype.concat(str [, …strN ])

A

Combines the text of two (or more) strings and returns a new string.

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

String.prototype.includes(searchString [, position])

String.prototype.endsWith(searchString [, length])

String.prototype.startsWith(searchString [, length])

A

Determines whether the calling string contains searchString.

Determines whether a string ends with the characters of the string searchString.

Determines whether the calling string begins with the characters of string searchString.

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

String.prototype.localeCompare(compareString [, locales [, options]])

A

Returns a number indicating whether the reference string compareString comes before, after, or is equivalent to the given string in sort order.

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

String.prototype.matchAll(regexp)

String.prototype.match(regexp)

String.prototype.search(regexp)

A

Returns an iterator of all regexp’s matches.

Used to match regular expression regexp against a string.

Search for a match between a regular expression regexp and the calling string.

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

String.prototype.padEnd(targetLength [, padString])

String.prototype.padStart(targetLength [, padString])

A

Pads the current string from the end || start with a given string and returns a new string of the length targetLength.

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

String.prototype.repeat(count)

A

Returns a string consisting of the elements of the object repeated count times.

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

String.prototype.replace(searchFor, replaceWith)

String.prototype.replaceAll(searchFor, replaceWith)

A

Used to replace occurrences of searchFor using replaceWith. searchFor may be a string or Regular Expression, and replaceWith may be a string or function.

17
Q

String.prototype.slice(beginIndex[, endIndex])

String.prototype.substring(indexStart [, indexEnd])

A

Extracts a section of a string and returns a new string.

Returns a new string containing characters of the calling string from (or between) the specified index (or indices).

18
Q

String.prototype.split([sep [, limit] ])

const array = […string]

A

Returns an array of strings populated by splitting the calling string at occurrences of the substring sep.

19
Q

String.prototype.toLocaleLowerCase( [locale, …locales])

String.prototype.toLocaleUpperCase( [locale, …locales])

A

The characters within a string are converted to lowercase || uppercase while respecting the current locale.

For most languages, this will return the same as toLowerCase() || toUpperCase()

20
Q

String.prototype.trim()

String.prototype.trimStart()

String.prototype.trimEnd()

A

Trims whitespace from the beginning and end of the string.

21
Q

parseInt()

A

The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).

22
Q

parseFloat()

A

The parseFloat() function parses an argument (converting it to a string first if needed) and returns a floating point number.