bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/TypeScript/TypeScript Core
TypeScript•TypeScript Core

TypeScript Simple Types

TypeScript enhances JavaScript by adding static types.

JavaScript and TypeScript Primitives

The most basic types in TypeScript are called primitives .

These types form the building blocks of more complex types in your applications.

TypeScript includes all JavaScript primitives plus additional type features.

Here are the five primitive types you'll use most often:

Boolean

Represents true/false values.

Used for flags, toggles, and conditions.

Example

let isActive: boolean = true;
let hasPermission = false; // TypeScript infers 'boolean' type

Number

Represents both integers and floating-point numbers.

TypeScript uses the same number type for all numeric values.

Example

let decimal: number = 6;
let hex: number = 0xf00d;       // Hexadecimal
let binary: number = 0b1010;     // Binary
let octal: number = 0o744;      // Octal
let float: number = 3.14;      // Floating point

String

Represents text data.

Can use single quotes ('), double quotes ("), or backticks (`) for template literals.

Example

let color: string = "blue";
let fullName: string = 'John Doe';
let age: number = 30;
let sentence: string = `Hello, my name is ${fullName} and I'll be ${age + 1} next year.`;

BigInt (ES2020+)

Represents whole numbers larger than 2 53 - 1.

Example

const hugeNumber = BigInt(9007199254740991);

Symbol

Creates unique identifiers.

Useful for creating unique property keys and constants.

Example

const uniqueKey: symbol = Symbol('description');
const obj = {
  [uniqueKey]: 'This is a unique property'
};
console.log(obj[uniqueKey]); // "This is a unique property"

Previous

TypeScript Getting Started

Next

TypeScript Explicit Types and Inference

This chapter

Overview
40

Lessons

241m

Read time

1. TypeScript Tutorial2. TypeScript Introduction3. TypeScript Getting Started4. TypeScript Simple Types5. TypeScript Explicit Types and Inference6. TypeScript Special Types7. TypeScript Arrays8. TypeScript Tuples9. TypeScript Object Types10. TypeScript Enums11. TypeScript Type Aliases and Interfaces12. TypeScript Union Types13. TypeScript Functions14. TypeScript Casting15. TypeScript Classes16. TypeScript Basic Generics17. TypeScript Utility Types18. TypeScript Keyof19. TypeScript Null & Undefined20. TypeScript Definitely Typed21. TypeScript 5.x Updates22. TypeScript Configuration23. TypeScript with Node.js24. TypeScript with React25. TypeScript Tooling26. TypeScript Advanced Types27. TypeScript Type Guards28. TypeScript Conditional Types29. TypeScript Mapped Types30. TypeScript Type Inference31. TypeScript Literal Types32. TypeScript Namespaces33. TypeScript Index Signatures34. TypeScript Declaration Merging35. TypeScript Async Programming36. TypeScript Decorators37. TypeScript in JavaScript Projects (JSDoc)38. TypeScript Migration Guide39. TypeScript Error Handling40. TypeScript Best Practices

On this page

JavaScript and TypeScript PrimitivesBooleanNumberStringBigInt (ES2020+)Symbol