Working with Text
7 min · TypeScript
Join typed strings, use template literals, and call string methods safely.
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.
Rena
Your AI tutor. She walks you through each step.
Asking for help is part of coding. Rena reads your code and gives you a hint. She is free with an account: 20 hints a day.