← Back to list

Understanding Data Types in TypeScript: From Numbers to Booleans

Welcome back to our TypeScript journey! In this blog post, we’ll explore the basics of data types in TypeScript. Understanding data types…

Omayer Ahmad · 2024-05-12 03:39 · 0 claps · 1.2 min read
#typescript #datatypes-in-typescript #datatypes-in-javascript #basic-typescript
Open on Medium ↗
Wiki topics: 🌐 · Web Development

Understanding Data Types in TypeScript: From Numbers to Booleans

Welcome back to our TypeScript journey! In this blog post, we’ll explore the basics of data types in TypeScript. Understanding data types is crucial for writing robust and maintainable code. Let’s dive in!

Numbers

In TypeScript, numbers are represented using the number data type. This includes both integers and floating-point numbers. Here's an example:

let count: number = 42;
let price: number = 10.99;

Strings

Strings represent text data and are enclosed in single (‘ ‘) or double (“ “) quotes. Here’s how you can declare string variables:

let message: string = "Hello, TypeScript!";
let name: string = 'Alice';

Booleans

Booleans represent logical values: true or false. They're commonly used in conditional statements and logical operations. Here's an example:

let isLogged: boolean = true;
let hasPermission: boolean = false;

Arrays

Arrays allow you to store multiple values of the same type. You can declare arrays using square brackets [] and specify the data type of its elements. Here's how you can create an array of numbers:

let numbers: number[] = [1, 2, 3, 4, 5];

Any

The any type allows you to assign values of any type to a variable. While it provides flexibility, its use should be minimized to maintain type safety. Here's an example:

let data: any = 42;
data = "Hello, TypeScript!";

Summary

Understanding data types is essential for writing clean and maintainable TypeScript code. By leveraging TypeScript’s type system, you can catch errors early in the development process and improve code quality.

In the next blog post, we’ll explore more advanced TypeScript concepts. Stay tuned for more TypeScript goodness!


메타데이터
post_id
80a6a7ea6291
slug
understanding-data-types-in-typescript-from-numbers-to-booleans-80a6a7ea6291
url
https://medium.com/@coderomayer/understanding-data-types-in-typescript-from-numbers-to-booleans-80a6a7ea6291
canonical_url
https://medium.com/@coderomayer/understanding-data-types-in-typescript-from-numbers-to-booleans-80a6a7ea6291
author_url
https://medium.com/@coderomayer
status
ok
fetched_at
2026-06-09 15:37:30