Menu
Coddy logo textTech

Basic Types: str, num, boolean

Part of the Introduction To TypeScript section of Coddy's JavaScript journey — lesson 6 of 73.

TypeScript has three fundamental primitive types that form the building blocks of most applications: string, number, and boolean. These types allow you to enforce what kind of data your variables can hold.

The string type is used for text data. You can declare a string variable like this:

let productName: string = "Laptop";

The number type handles all numeric values in TypeScript - both integers and decimals:

let price: number = 999.99;

The boolean type represents true/false values, perfect for flags and conditions:

let inStock: boolean = true;
challenge icon

Challenge

Easy

Create three separate variables with explicit type annotations and appropriate values:

Declare a variable named productName with type string and assign it the value "Gaming Mouse".

Declare a variable named price with type number and assign it the value 49.99.

Declare a variable named inStock with type boolean and assign it the value true.

Print all three variables to the console on separate lines in the order they were declared.

Try it yourself

// TODO: Write your code here
// Declare the three variables with explicit type annotations and values
// Then print them to the console
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction To TypeScript