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
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.