WHAT'S NEW
TypeScript · Lesson 01 of 11

Introduction to TypeScript

Take your JavaScript skills to the next level! Discover how TypeScript helps you write clearer code, catch mistakes earlier, and build reliable applications with confidence.

TypeScript Getting Started Static Typing Hands-On Practice
● ● ●   hello.ts
const message: string =
  "Hello, TypeScript!";

console.log(message);
CONSOLE OUTPUT
> Ready to run…
01 / Getting Started

Meet TypeScript

JavaScript powers interactive websites, web applications, and much more. It’s flexible and powerful, but that flexibility can sometimes make mistakes difficult to catch.

TypeScript builds on JavaScript by adding a type system. It helps developers describe what kind of information their code should work with, making certain mistakes easier to spot before the code runs.

If you already know a little JavaScript, you’re off to a great start. TypeScript uses familiar JavaScript syntax while introducing tools that help you write more predictable code.

Remember: TypeScript is a superset of JavaScript. Valid JavaScript syntax is also valid TypeScript syntax, although TypeScript may report type errors in code that JavaScript would accept.
02 / Why TypeScript?

Catch Mistakes Before They Become Problems

Imagine creating a variable to store someone’s age. You expect a number, but somewhere in your program, a piece of text accidentally gets assigned instead.

JavaScript — a possible mistake
let age = 25;
age = "twenty-five";

JavaScript allows this because variables can hold values of different types. That flexibility can be useful, but it can also lead to unexpected behavior later.

TypeScript — catching the mistake
let age: number = 25;
age = "twenty-five"; // Type error!

The : number annotation tells TypeScript that age should contain a number. Assigning text conflicts with that expectation, so TypeScript reports an error.

Why it matters: Finding a type error while writing code is often easier than discovering an unexpected result after your application is running.
03 / Understanding Types

Give Your Data a Clear Identity

TypeScript includes types for common kinds of information. Three you’ll use frequently are string, number, and boolean.

basic-types.ts
const username: string = "Alex";
const score: number = 100;
const isLearning: boolean = true;

console.log(username);
console.log(score);
console.log(isLearning);
Console Output:
Alex 100 true

A string represents text, a number represents numeric values, and a boolean represents either true or false.

You’ll explore these types in much greater detail in the next lesson.

04 / Type Inference

TypeScript Can Figure Things Out

Here’s something useful: you don’t always need to write a type annotation. TypeScript can often determine a variable’s type from the value you give it.

type-inference.ts
let city = "Los Angeles";
let temperature = 72;

city = "San Diego";       // Allowed
temperature = 75;         // Allowed

// temperature = "warm";  // Type error

TypeScript infers that city is a string and temperature is a number. It can then check later assignments against those types.

Good habit: Use type inference when the intended type is obvious. Add explicit annotations when they improve clarity or communicate an important requirement.
05 / TypeScript and JavaScript

How Does TypeScript Run?

Browsers normally execute JavaScript, not TypeScript source code. TypeScript-specific syntax, such as : string, needs to be removed before the code can run in a browser.

The TypeScript compiler performs this conversion. The process is commonly called transpilation.

hello.ts — TypeScript source
const message: string = "Hello, TypeScript!";
console.log(message);
hello.js — compiled JavaScript
const message = "Hello, TypeScript!";
console.log(message);

Notice that the type annotation disappears. Types help TypeScript check your program, but they don’t become runtime JavaScript instructions.

Important: TypeScript checks types during development. It doesn’t automatically validate data at runtime. A program can still encounter runtime errors, so testing remains essential.
06 / Your First TypeScript Program

Write a Friendly Greeting

Let’s combine what you’ve learned into a small program that stores information and prints a personalized greeting.

greeting.ts
const developer: string = "Alex";
const course: string = "TypeScript";

console.log("Hello, " + developer + "!");
console.log("Welcome to " + course + ".");
Console Output:
Hello, Alex! Welcome to TypeScript.

Each variable has a clear type, and console.log() prints the resulting messages. If you try assigning a number to one of these string variables, TypeScript can report the mismatch.

07 / Putting It Together

You’re Ready to Write TypeScript!

You’ve learned what TypeScript is, why types are useful, and how TypeScript becomes JavaScript before running in a browser.

Now it’s time to experiment. You’ll write a small program, change its values, and see the results in a real TypeScript sandbox.

Don’t worry about memorizing every type or rule yet. Focus on understanding how types describe your data and help you catch mistakes.

🚀 mC0de Challenge

Create Your TypeScript Introduction

Write a short program that introduces you as a developer using TypeScript variables and types.

Your Mission

  1. Change the developer variable to your own name.
  2. Change the favoriteLanguage variable to a programming language you enjoy or want to learn.
  3. Give the lessonsCompleted variable a new numeric value.
  4. Use console.log() to display your personalized introduction.
  5. Run your program and check the console output.
Extra challenge: Try assigning a string to lessonsCompleted. What error does TypeScript report? Restore a number afterward and run your program again.
💻 Interactive TypeScript Sandbox

Write Your First TypeScript Program!

Edit the variables and run your program. TypeScript will check your code, compile it into JavaScript, and display the output below.

Console Output
Lesson 01 Recap

What You’ve Learned

You’ve Taken Your First Step Into TypeScript!

You’re beginning to write code with more confidence. You can now:

  • Explain what TypeScript is and how it relates to JavaScript.
  • Understand why static typing helps catch mistakes.
  • Recognize string, number, and boolean types.
  • Describe how TypeScript infers types from values.
  • Understand how TypeScript compiles into JavaScript.
  • Write and run a simple TypeScript program.

Next up: Variables and Types — explore TypeScript’s type system and learn how to work with different kinds of data!

Your Learning Journey

0 / 11 Completed

Keep going! Every completed lesson brings you closer to building reliable applications with TypeScript.

🎉

Nice Work!

You’ve discovered what TypeScript is, explored how types help catch mistakes, and written your first TypeScript program. You’re officially on your way to building clearer, more reliable applications!

PIX0
</> {} JS 01
0101 </> CSS JS HTML PIX0 const {} 1010 async mC0de function return 0101 <div> 1010 PIX0 CSS JS HTML const {} 0101 mC0de
PIX0 // WORLD OF CODE
PIX0 IS PREPARING SOMETHING AWESOME FOR YOU 0%