TypeScript Primitives: String, Number, and Boolean Type
Last Updated :
28 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)
Output:

Number Type
The number data type represents numeric values, both integers and floating-point numbers.
Syntax
let variableName: number = numericValue;
Where,
- variableName: This is the name of the variable.
- number: This is the type annotation specifying that the variable should store a numeric value (integer or floating-point).
- numericValue: This is the initial numeric value assigned to the variable.
Example: In this example, we will learn about number
JavaScript
let num: number = 30;
let float: number = 19.99;
console.log(num)
console.log(float)
Output:

Boolean Type
The boolean data type represents a binary value, which can be either true or false. It is often used for conditions and logical operations.
Syntax
let variableName: boolean = true | false;
Where,
- variableName: This is the name of the variable.
- boolean: This is the type annotation specifying that the variable should store a boolean value, which can be true or false.
- true or false: These are the initial boolean values assigned to the variable
Example: In this example, we will learn about boolean
JavaScript
let isStudent: boolean = true;
let hasPermission: boolean = false;
console.log(isStudent)
console.log(hasPermission)
Output:
Reference: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#the-primitives-string-number-and-boolean
Similar Reads
TypeScript Less Common Primitives Type TypeScript Less Common Primitives Type offers a rich set of primitive types to represent data. While most developers are familiar with types like number, string, boolean, and symbol, TypeScript also provides less common primitive types that can be incredibly useful in specific scenarios. These are s
2 min read
How to Convert String to Boolean in TypeScript ? In Typescript, sometimes you receive the data as strings but need to work with boolean values or identify the boolean equivalent of it.There are several approaches to convert string to boolean in TypeScript which are as follows:Table of ContentUsing Conditional StatementUsing JSON.parse() MethodUsin
4 min read
What are string literal types in TypeScript ? The string literal type was added in TypeScript version 1.8. String literal types work well with union types and type aliases in practice. These properties can be combined to give strings enum-like functionality. The string literal type allows you to specify a set of possible string values for a var
3 min read
How to Convert a Bool to String Value in TypeScript ? When we talk about converting a boolean to a string value in TypeScript, we mean changing the data type of a variable from a boolean (true or false) to a string (a sequence of characters). We have multiple approaches to convert a bool to a string value in TypeScript.Example: let's say you have a var
3 min read
TypeScript - Type Annotations and Type Inference TypeScript is a superset of JavaScript that adds static typing, helping developers catch errors early. Two core features are type annotations- where developers explicitly define variable, parameter, and return types, and type inference, where TypeScript automatically deduces types based on values or
5 min read