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:
TypeScript Primitives: String, Number, and Boolean Type
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.