Lesson 7: Working with Characters and Strings Flashcards

1
Q

What kind of type is Strings?

A

Primitive.

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

What is backslash () used for?

A

To escape a char in string. Makes regular char special and special char literal.

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

Show an example using backslash:

A

document.write(“Bob said, \ “I like that story." “)

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

What is the + operator used for?

A

Joining strings.

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

Show an example using the + operator:

A
let greeting = 'hello';
let name = 'molly';
let message = greeting + name;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

concat:

A

Joins strings and returns a copy of the joined string.

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

indexOf:

A

Returns the position of the first occurrence of a specified value in a string.

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

lastIndexOf:

A

Returns the position of the last occurrence of a specified value in a string.

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

Repeat:

A

Returns a new string with a specified number of copies of the string it was called on.

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

Replace:

A

Searches for a match between substring and a string, then replaces the substring with a new one.

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

Split:

A

Splits a string into an array of substrings, then returns the new array.

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

Substr:

A

Extracts a substring from a string beginning at a specified start position , and through the specified number of characters.

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

toLowerCase:

A

Converts a string to lowercase letters.

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

toUpperCase:

A

Converts a string to uppercase letters.

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

What does a Template String do?

A

Extracts variable values enclosed in it with the format of ${variable}

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

Show an example using Template String:

A
var total = 20;
var tax = 4;
msg = 'Total is ${total + tax} dollars)';
alert(msg);
17
Q

How do you define a string?

A

Enclosing it in single or double quotation marks.

18
Q

What does the ‘length’ property do?

A

It will return the number of characters in the string.

19
Q

Show an example using the length property:

A
var myString = "How long am I?";
alert(myString.length);
20
Q

What are some common Escape Sequences?

A
\t = tab
\" = double quote
\n = new line / line break