Working with Text
7 min · TypeScript
Join typed strings, use template literals, and call string methods safely.
TypeScript · Working with Text0/5 cleared
Enemy 1 of 5
This code joins two pieces of text with + and prints the result. Press Run to see Hello, Ada.
Why this works
Text values are strings: any sequence of characters inside quotes. Type them as string, and TypeScript will make sure that variable can only ever hold text, never accidentally a number or some other value later in the program.
Join two strings with + (concatenation), just like plain JavaScript. Because both greeting and name are explicitly typed as string here, there's no ambiguity about what + should do: TypeScript and JavaScript both treat it as gluing the text together.
You
Packet Wolf
Loading editor…
Sign up to fightThis one runs on our servers, so it needs a free account.