Lesson 7: Working with Characters and Strings Flashcards
What kind of type is Strings?
Primitive.
What is backslash () used for?
To escape a char in string. Makes regular char special and special char literal.
Show an example using backslash:
document.write(“Bob said, \ “I like that story." “)
What is the + operator used for?
Joining strings.
Show an example using the + operator:
let greeting = 'hello'; let name = 'molly'; let message = greeting + name;
concat:
Joins strings and returns a copy of the joined string.
indexOf:
Returns the position of the first occurrence of a specified value in a string.
lastIndexOf:
Returns the position of the last occurrence of a specified value in a string.
Repeat:
Returns a new string with a specified number of copies of the string it was called on.
Replace:
Searches for a match between substring and a string, then replaces the substring with a new one.
Split:
Splits a string into an array of substrings, then returns the new array.
Substr:
Extracts a substring from a string beginning at a specified start position , and through the specified number of characters.
toLowerCase:
Converts a string to lowercase letters.
toUpperCase:
Converts a string to uppercase letters.
What does a Template String do?
Extracts variable values enclosed in it with the format of ${variable}