Mozilla "strings" Flashcards

1
Q

The String object’s _________method returns a new string consisting of the single UTF-16 code unit located at the specified offset into the string.

A

charAt()

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

The ______ method concatenates the string arguments to the calling string and returns a new string.

A

concat()

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

The _______ method determines whether a string ends with the characters of a specified string, returning true or false as appropriate.

A

endsWith()

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

the endsWith() returns __________

A

a boolean

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

const str1 = ‘Cats are the best!’;

console.log(str1.endsWith('best', 17));
// expected output: 

const str2 = ‘Is this a question’;

console.log(str2.endsWith('?'));
// expected output:
A

true

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
const str1 = 'Cats are the best!';
console.log(str1.endsWith('best!', 17));
// expected output:
A

false

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

The __________method determines whether one string may be found within another string, returning true or false as appropriate.

A

includes()

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

includes() returns a _____________

A

boolean

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

The _____________method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.

A

indexOf()

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

var paragraph = ‘The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?’;

var searchTerm = 'dog';
var indexOfFirst = paragraph.indexOf(searchTerm);
console.log(indexOfFirst);
// expected output: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
A

40

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

The _____________ method returns the index within the calling String object of the last occurrence of the specified value, searching backwards from fromIndex. Returns -1 if the value is not found.

A

lastIndexOf()

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

The ______________ method returns the calling string value converted to uppercase (the value will be converted to a________ if it isn’t one).

A

toUpperCase()

string

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

The ____________ method returns the calling string value converted to lower case.

A

toLowerCase()

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

The ____________ method removes whitespace from both ends of a string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).

A

trim()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
var greeting = '   Hello world!   ';
console.log(greeting.trim());
A

“Hello world!”

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

The _____________ method removes whitespace from the end of a string. trimRight() is an alias of this method.

A

trimEnd()

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

var greeting = ‘ Hello world! ‘;

console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_);
// expected output: "   Hello world!";
A

greeting.trimEnd()

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

The _____________ method removes whitespace from the beginning of a string. trimLeft() is an alias of this method

A

trimStart()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
var greeting = '   Hello world!   ';
console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_);
// expected output: "Hello world!   ";
A

greeting.trimStart()

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

The ____________ method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.

A

split()

21
Q

var str = ‘The quick brown fox jumps over the lazy dog.’;

var words = str.split(' ');
console.log(words[3]);
// expected output:
A

“fox”

22
Q

var str = ‘The quick brown fox jumps over the lazy dog.’;

var words = str.split(' ');
console.log(\_\_\_\_\_\_\_\_\_\_);
// expected output: "fox"
A

words[3]

23
Q

var str = ‘The quick brown fox jumps over the lazy dog.’;

var chars = str.split('');
console.log(chars[8]);
// expected output:
A

“k”

24
Q

var str = ‘The quick brown fox jumps over the lazy dog.’;

var chars = str.split('');
console.log(\_\_\_\_\_\_\_\_\_\_);
// expected output: "k"
A

chars[8]

25
Q

The split() method splits a String object into an __________ of strings by separating the string into substrings, using a specified separator string to determine where to make each split.

A

array

26
Q

split()

A

method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.

27
Q

includes()

A

determines whether one string may be found within another string, returning true or false as appropriate.

28
Q

The ___________method returns the part of the string between the start and end indexes, or to the end of the string.

A

substring()

29
Q

var str = ‘Mozilla’;

console.log(str.substring(1, 3));
// expected output: 
console.log(str.substring(2));
// expected output:
A

“oz”

“zilla”

30
Q

str.substring(_________[,_________])

A

indexStart

indexEnd

31
Q
const str1 = 'Cats are the best!';
console.log(str1.endsWith('best!'));
A

true

32
Q

The __________method pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end (right) of the current string.

A

padEnd()

33
Q

const str1 = ‘Breaded Mushrooms’;

console.log(str1.padEnd(25, '.'));
// expected output: 

const str2 = ‘200’;

console.log(str2.padEnd(5));
// expected output:
A

“Breaded Mushrooms……..”

“200 “

34
Q

The ______ method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start (left) of the current string.

A

padStart()

35
Q

const str1 = ‘5’;

console.log(str1.padStart(2, 0));
// expected output:
A

“05”

36
Q
const fullNumber = '2034399002125581';
const last4Digits = fullNumber.slice(-4);
const maskedNumber = last4Digits.padStart(fullNumber.length, '*');
console.log(maskedNumber);
// expected output:
A

****5581”

37
Q

const str1 = ‘5’;

console.log(str1.padStart(2));
// expected output:
A

” 5”

38
Q

The _______ method extracts a section of a string and returns it as a new string, without modifying the original string.

A

slice()

39
Q

var str = ‘The quick brown fox jumps over the lazy dog.’;

console.log(str.slice(31));
// expected output:
A

“the lazy dog.”

40
Q

var str = ‘The quick brown fox jumps over the lazy dog.’;

console.log(str.slice(4, 19));
// expected output:
A

“quick brown fox”

41
Q

var str = ‘The quick brown fox jumps over the lazy dog.’;

;console.log(str.slice(-4));
// expected output:
A

“dog.

42
Q

var str = ‘The quick brown fox jumps over the lazy dog.’;

console.log(str.slice(-9, -5));
// expected output:
A

“lazy”

43
Q

The ___________ method determines whether a string begins with the characters of a specified string, returning true or false as appropriate.

A

startsWith()

44
Q
const str1 = 'Saturday night plans';
console.log(str1.startsWith('Sat', 3));
// expected output:
A

false

45
Q
const fullNumber = '2034399002125581';
const last4Digits = fullNumber.slice(-4)

console.log(last4Digits);

A

5581

46
Q

‘abc’.padStart(1); //

A

“abc”

47
Q

‘abc’.padStart(10, “foo”); //

A

“foofoofabc”

48
Q

‘abc’.padStart(6,”123465”); //

A

“123abc”

49
Q

‘abc’.padStart(8, “0”); //

A

“00000abc”