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}
Show an example using Template String:
var total = 20; var tax = 4; msg = 'Total is ${total + tax} dollars)'; alert(msg);
How do you define a string?
Enclosing it in single or double quotation marks.
What does the ‘length’ property do?
It will return the number of characters in the string.
Show an example using the length property:
var myString = "How long am I?"; alert(myString.length);
What are some common Escape Sequences?
\t = tab \" = double quote \n = new line / line break