All lessons

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

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...

Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: Hello, Ada