The Built-in Types
Meet the three types you'll use most: string, number, boolean.
1const coder: string = "Ada";
2const age: number = 10;
3const likesPizza: boolean = true;
4console.log(`${coder} is ${age} and likes pizza: ${likesPizza}`);
$ npx tsc main.ts
$ node main.js
Ada is 10 and likes pizza: true
Every line, explained
const coder: string = "Ada";- string is the type for text. The built-in type names are all lowercase: string, number, boolean.
const age: number = 10;- number covers every kind of number: whole numbers and decimals alike. (Some languages split these in two; TypeScript keeps it simple.)
const likesPizza: boolean = true;- boolean allows exactly two values: true or false.
console.log(`${coder} is ${age} and likes pizza: ${likesPizza}`);- console.log(...) works exactly as it does in JavaScript; TypeScript IS JavaScript underneath, so everything from Intro to JavaScript still applies. Template literals with ${...} work in TypeScript too.