TypeScript Primitives: String, Number, and Boolean Type
Last Updated :
24 Apr, 2025
In this article, we are going to learn about TypeScript primitives: string, number, and boolean Type in Typescript. These are the most used and basic data types. Below we will learn about string, number, and boolean in detail.
TypeScript Primitive DataTypes
Similar to JavaScript's mostly used data types TypeScript has mainly 3 primitives
- String: TypeScript Strings are similar to sentences. They are made up of a list of characters, which is essentially just an “array of characters, like “Hello GeeksforGeeks” etc.
- Number: Just like JavaScript, TypeScript supports number data type. All numbers are stored as floating point numbers.
- Boolean: The most basic datatype is the simple true/false value, which JavaScript and TypeScript call a boolean value.
String Type
The string data type represents text or sequences of characters. Strings are enclosed in single or double quotes in JavaScript and TypeScript.
Syntax
let variableName: string = "value";
Where
- variableName: This is the name of the variable.
- string: This is the type annotation specifying that the variable should store a string.
- "value": This is the initial value assigned to the variable.
Example: In this example, we will learn about string
JavaScript
let gfg: string = "GeeskforGeeks";
console.log(gfg)