Typescript Primitive Types
get familiar with basic types like string, number, boolean, null, undefined, and any.
In TypeScript, primitive types represent the most basic data structures, and they are essential building blocks. Here’s a quick overview of each:
string
Represents text data.
Example:
number
Represents numerical values, both integers and floating-point numbers.
Example:
boolean
Represents true/false values.
Example:
null
Represents an explicitly empty or null value. It is technically a subtype of all other types.
Example:
undefined
Used when a variable is declared but has not been assigned a value. It’s also a subtype of all types.
Example:
any
Allows any kind of value to be assigned, making it the most flexible type. Useful when migrating JavaScript code or when you don’t know the type ahead of time.
Example:
These types provide the foundation for working with TypeScript, helping enforce type safety across variables and function parameters.