JavaScript Strings and String
Methods
• A string is a sequence of
characters.
• It can be enclosed in single (' '),
double (" "), or backticks (` `).
What is a
• Example:
String?
Returns the number of
characters in a string.
length • Example:
Converts string to
upper or lower case.
toUpperCase() /
toLowerCase()
• Example:
Returns the character
at a specific position.
charAt(index) • Example:
Finds the position of
the first match.
indexOf • Example:
(substring)
Extracts part of a
string.
slice(start, • Example:
end)
Similar to slice but doesn't
accept negative indexes
substring(star • Example:
t, end)
Replaces the first
matched string.
replace(searc
h, • Example:
replacement)
Checks if a string
contains a substring.
includes(subst • Example:
ring)
Splits string into an array
based on a separator.
split(separato • Example:
r)
Removes white spaces
from both ends of a string.
• Example:
trim()
Allows embedded variables
BONUS: and multiline strings.
Template
Literals (` • Example:
backticks)
Practice Tasks
• Get the first and last character of a string.
• Count how many times a word appears in a
sentence.
• Check if a string is a palindrome.
• Validate a user input field (trim, length).
• Highlight keywords in a paragraph.
• Reverse a Sentence
• Capitalize Each Word in a Sentence