In TypeScript, simple types are the core foundational building blocks.
They represent the most basic forms of data you can store and manipulate.
The main simple types include strings, numbers, and booleans.
Mastering these is key to creating easily understandable web apps.
A string represents textual data, enclosed in single or double quotes.
Strings are essential for rendering user interfaces and readable content.
Search engines easily parse string outputs when optimizing for SEO.
let firstName: string = "Akash";
let greeting: string = `Hello, ${firstName}!`;
console.log(greeting);
The number type in TypeScript represents both integer and floating-point values.
Unlike some other languages, TypeScript does not separate integers and floats.
This makes math operations highly consistent and straightforward.
let age: number = 25; let price: number = 19.99;let total: number = age + price;
console.log("Total is:", total);
Booleans are logical entities that can strictly be true or false.
They are commonly used in conditional statements like if blocks.
Using booleans clarifies the flow and state of your web applications.
let isPublished: boolean = true; let hasErrors: boolean = false;if (isPublished) { console.log("Article is live!"); }
Which of the following is a simple type in TypeScript?
Simple types are used absolutely everywhere in TypeScript codebases.
By defining them, you prevent many common runtime bugs.
Next, we will explore how TypeScript can automatically guess these types!