0
0
Typescriptprogramming~15 mins

Type annotation on variables in Typescript - Mini Project: Build & Apply

Choose your learning style9 modes available
Type annotation on variables
📖 Scenario: You are creating a simple program to store information about a book. You want to make sure the types of the variables are clear and correct.
🎯 Goal: Learn how to add type annotations to variables in TypeScript to make your code safer and easier to understand.
📋 What You'll Learn
Create variables with explicit type annotations
Use string and number types
Assign correct values matching the types
Print the variables to see their values
💡 Why This Matters
🌍 Real World
Type annotations help developers avoid mistakes by clearly stating what kind of data each variable should hold. This is very useful in real projects to prevent bugs.
💼 Career
Many programming jobs require writing clear and safe code. Knowing how to use type annotations in TypeScript is important for frontend and backend development.
Progress0 / 4 steps
1
Create variables with type annotations
Create a variable called title with type string and value "The Great Gatsby". Create a variable called pages with type number and value 180.
Typescript
Need a hint?

Use let variableName: type = value; to add type annotations.

2
Add a boolean variable with type annotation
Add a variable called isAvailable with type boolean and value true.
Typescript
Need a hint?

Boolean variables use the type boolean and values true or false.

3
Change the value of a variable with the correct type
Change the value of pages to 200. Make sure the type annotation stays the same.
Typescript
Need a hint?

Keep the type annotation : number and update the value after the equals sign.

4
Print all variables to the console
Write three console.log statements to print the values of title, pages, and isAvailable.
Typescript
Need a hint?

Use console.log(variableName); to print each variable.