Lesson 7: Working with Characters and Strings Flashcards Preview

IMG-111 Mid-term > Lesson 7: Working with Characters and Strings > Flashcards

Flashcards in Lesson 7: Working with Characters and Strings Deck (20)
Loading flashcards...
1
Q

What kind of type is Strings?

A

Primitive.

2
Q

What is backslash () used for?

A

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

3
Q

Show an example using backslash:

A

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

4
Q

What is the + operator used for?

A

Joining strings.

5
Q

Show an example using the + operator:

A
let greeting = 'hello';
let name = 'molly';
let message = greeting + name;
6
Q

concat:

A

Joins strings and returns a copy of the joined string.

7
Q

indexOf:

A

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

8
Q

lastIndexOf:

A

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

9
Q

Repeat:

A

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

10
Q

Replace:

A

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

11
Q

Split:

A

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

12
Q

Substr:

A

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

13
Q

toLowerCase:

A

Converts a string to lowercase letters.

14
Q

toUpperCase:

A

Converts a string to uppercase letters.

15
Q

What does a Template String do?

A

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

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