Beginner · 10 min
Types and values
Use basic type annotations and distinguish type checking from execution.
Describe a value
TypeScript checks JavaScript before it runs. A type annotation describes an allowed value; it does not convert the value. This course assumes basic JavaScript knowledge.
const name: string = "Ada";
const tickets: number = 2;
console.log(name + ": " + tickets);Output
Ada: 2
Types disappear at runtime
Annotations are removed when TypeScript becomes JavaScript. The playground checks your types before running the result. Runtime behavior still follows JavaScript rules.
const ready: boolean = true;
console.log(typeof ready);Output
boolean
Put it into practice
- Read the types and predict the output before running the examples.
- Complete the task, then check your understanding with the practice questions.
Try it yourself
Code runs on this device. When you are signed in, drafts sync to your account.
Use a numeric value
Assign the number 4 to "count" and display it. Keep the number annotation.
Remove the quotation marks around 4. Changing a type annotation does not convert a string.