- 01Getting Started
- 02Your First Output (console.log)
- 03Variables and Type Annotations (number/string/boolean)
- 04Array Types
- 05Function Types (Parameters and Return Values)
- 06Optional Parameters and Default Parameters
- 07Interfaces (interface)
- 08Optional Properties (?)
- 09Type Aliases (type)
- 10Union Types
- 11Literal Types
- 12enum (Enumerated Types)
- 13Classes and Types
- 14Inheritance (extends) and Implementing an Interface (implements)
- 15Generics (<T>)
- 16Tuple Types
- 17The any and unknown Types
- 18Type Assertions (as)
- 19The readonly Modifier
- 20[Applied] Build a Mini Inventory Management System
Your First Output (console.log)
This lesson covers the basics of output in TypeScript, plus your first taste of type annotations. It's for anyone searching "TypeScript console.log tutorial."
console.log() prints text to the screen (the console) โ written exactly the same way as in JavaScript. It helps to think of TypeScript as "JavaScript with a type-checking feature added on top."
The example writes let message: string = "Hello, TypeScript!";, adding a type annotation, : string, right after the variable name. This is how you declare to TypeScript: "only strings go into this variable."
A common early mistake is assuming you have to write a type every single time โ you don't. TypeScript actually infers the type automatically from the assigned value, so : string can be omitted and the code still works. It's still worth practicing writing types explicitly at first, until it feels natural.
In real projects, having types means your editor can offer much stronger autocomplete and catch typos as you type, which is why so many large JavaScript projects have migrated to TypeScript.
๐งช This site can't compile or run TypeScript directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
