Skip to content
dreamcode
dreamcode
Map
Types
Lesson 1 of 26
+15 XP on finish
TYPESCRIPTChapter 1 · TS Basics

Typing your variables

TypeScript is JavaScript with types. You annotate a variable with : type to specify the data it should hold. These annotations are checked during compilation and stripped in the running JavaScript.

Worked example

How it reads

  • : string / : number / : boolean specify variable types
  • Types are strictly checked by the compiler before running
Cloud tip: Let inference do the work: if you assign a value immediately, TypeScript can infer the type automatically.
index.ts
TYPESCRIPT
type-checked, then run in your browser
Console
Run your code to see its output here.
YOUR TURN

Add a boolean variable visible set to true and log it after the sentence.

Press Run to check your work.