CC-06: String Mutations
Last updated
Last updated
with Carmen Salas • 2024/10/10
Strings are made up of chars
. Every char
in a string has a corresponding position index
, allowing direct access to them. As a result, strings are iterable, and indices start at 0
Some string properties/methods:
.length
returns the size of the string
.toUpperCase()
and .toLowerCase()
works for both char
and string
. This is because char
in JavaScript is also a string
.
Various ways to add strings
using the +
/+=
operator (can be between a str
<->str
, str
<->num
, etc.)
using String
methods like .concat()
, .padEnd()
, .repeat()
Declare a function named reverseString
that takes in a string argument and returns the reversed version of the string, without using any .reverse()
JavaScript methods. Hint: How can you use a loop iterate through a string backwards?
Declare a function named reverseZigZagString
that takes in a string argument and returns the reversed version of the string with characters alternating in uppercase and lowercase, without using any .reverse()
JavaScript methods.