Strings Flashcards
Get a fucking job
What are the two ways of accessing a character?
Using the brackets with an index ([i]) or using the charAt() method.
What are template strings?
Also known as template literals. They’re literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded expressions, and special constructs called tagged templates.
How is concatenation performed?
With the instance method concat(), this method concatenates the string arguments to this string and returns a new string.
What is .trim()?
An instance method that removes whitespace from both ends of this string, and returns a new string, without modifying the original string.
What is . substring()?
An instance method that returns the part of this string from the start index up to and EXCLUDING the end index, or to the end of the string if no end index is passed.
What is .startsWith()?
Instance method that determines if this string starts with the given string. Returns a boolean.
What is .replaceAll()?
Instance method that returns a new string with all matches of a pattern replaced by a replacement. The original string is left unchanged.
What is .replace()?
Instance method that returns a new string with the first match of a string pattern replaced by a replacement. The original string is left unchanged. If the pattern is a RegEx, all occurences change.
What is .at()?
An instance method that returns the character at the index specified. Returns undefined if the index doesn’t exists in the string.
What’s the difference between .charAt() and .at()?
.charAt() is an older method, .at() was introduced in ECMAScript 2022 (ES13). Also, charAt always returns a string, if the index is out of bounds, it returns an empty string, while the .at() method returns undefined.
Also .at() accepts negative integers.