QuickDevGuide

Home › JavaScript

Strings & Template Literals — JavaScript

Strings are immutable sequences of UTF-16 code units. Every string method returns a new string — the original never changes. Creating strings Single quotes, double quotes and template literals (backticks) all create strings. Template literals add ${expression} interpolation and multi-line text. Most-used methods Task Method Search includes(), startsWith(), endsWith(), indexOf() Extract slice(start, end), at(-1), substring() Transform toUpperCase(), toLowerCase(), trim(), padStart(), repeat() Split / join split(",") → array, array.join(", ") → string Replace replace() (first), replaceAll() (every match) Compare localeCompare() for correct alphabetical sorting Tagged templates A function placed before a template literal receives the raw string parts and values separately — used by…

Key Takeaways