Course contentsShow
← TypeScript
Lesson 87 of 1,7963. Basic TypesFree lesson

The number Type

Understand how all numeric values—integers, floats, hex, binary—share one type: number.

The number Type

What you'll learn: How TypeScript uses a single number type to represent all kinds of numeric values.

One Type to Rule Them All

In TypeScript, there's no separate type for integers, decimals, or different number formats. Whether you're working with 42, 3.14159, 0xFF (hexadecimal), or 0b1010 (binary), they all share the same type: number.

This mirrors JavaScript's behavior, where all numbers are stored as floating-point values under the hood. TypeScript embraces this simplicity rather than fighting it.

Why This Matters

Coming from languages like Java or C#, you might expect separate types like int, float, or double. TypeScript takes a different approach:

let age: number = 25;
let price: number = 19.99;
let hexColor: number = 0xFF5733;
let binary: number = 0b1010;

// All of these are simply "number"

Think of number as a universal container for anything numeric—it's like having one drawer labeled "numbers" instead of separate drawers for "whole numbers," "decimals," and "special formats."

The Takeaway

The number type is flexible by design. You don't need to worry about whether your value has decimal places, how it's formatted in your code, or what range it falls into. TypeScript (and JavaScript) treat them all uniformly as number.

Key Takeaway: In TypeScript, all numeric values—integers, floats, hexadecimal, binary—are represented by the single number type.