CC-06: String Mutations
with Carmen Salas • 2024/10/10
Strings
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:
.lengthreturns the size of thestring.toUpperCase()and.toLowerCase()works for bothcharandstring. This is becausecharin JavaScript is also astring.
Concatenation
Various ways to add strings
using the
+/+=operator (can be between astr<->str,str<->num, etc.)using
Stringmethods like.concat(),.padEnd(),.repeat()
Carmen's Code Snippets
Code Challenge
Declare a function named
reverseStringthat 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
reverseZigZagStringthat 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.
Last updated