String Methods Flashcards

(10 cards)

1
Q

What are the 2 operators used to build and concatenate strings?
What is a string method you could also use to achieve this?

A

+
+=

const str1 = 'Hello';
const str2 = 'World';
str1.concat(' ', str2);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 2 ways to access a single character in a string?

A
  1. charAt() = string.charAt(i)
  2. bracket notation = string[i]

*When using bracket notation for character access, attempting to delete or assign a value to these properties will not succeed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
let s= "1+2"
what does eval(s) return?
A

3

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

What symbol is used for escape notation within a string literal?

A

\

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

What can you include inside of string “” to indicate that the string value will continue on the next line?

A
\
let str= "This is
\a very long string";
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

.includes()

  1. What is it’s purpose?
  2. What is the syntax?
  3. What does it return?
A
  1. determines whether one string can be found within another string
  2. myString.includes(“word”)
  3. true/false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

.endsWith()

  1. What is it’s purpose?
  2. What is the syntax?
  3. What does it return?
A
  1. determines whether a string ends with the characters of a specified string
  2. myString.endsWith(“hello”)
  3. true/false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What method(s) could you use to determine if a string can be found within another string?

A

.includes()
myString.includes(“another string”)
returns true/false

indexOf()
myString.indexOf(searchTerm)
returns -1 if term does not exist in the string

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

What method could you use to determine if a string ends with the characters of a specified string?

A

.endsWith()
myString.endsWith(“another string”)
returns true/false

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

.indexOf()

  1. What is it’s purpose?
  2. What is the syntax?
  3. What does it return?
A
  1. returns the index of first occurring index of a specified value within a string
2. const paragraph = 'The quick brown fox jumps';
const searchTerm = 'fox';
const indexOfFirst = paragraph.indexOf(searchTerm);
  1. the index of the specified value
    * returns -1 if search term does not exist
How well did you know this?
1
Not at all
2
3
4
5
Perfectly