Chapter 6 of 16All chapters
Chapter 6 of 16
Strings
Quotes, templates and the useful methods.
Writing text
Single and double quotes behave identically. Backticks make a template literal, which can span lines and interpolate with ${}, so `Hello ${name}` reads better than joining with plus.
- Strings are immutable, so every method returns a new string.
- The plus operator joins if either side is a string, which is why "5" + 3 gives "53".
Methods worth knowing
slice takes a section, split turns text into an array, trim removes whitespace, and includes, startsWith and endsWith answer questions without a regular expression.