set a boolean in typescript

To set a boolean in TypeScript, you first need to declare a variable of type boolean:

index.ts
let isTrue: boolean;    // declare a boolean variable
54 chars
2 lines

Then, you can assign a value to the variable using the boolean literals true or false:

index.ts
isTrue = true;          // assign true to isTrue
49 chars
2 lines

or

index.ts
isTrue = false;         // assign false to isTrue
50 chars
2 lines

Alternatively, you can declare and set a boolean variable in a single line:

index.ts
let isTrue: boolean = true;   // declare and set isTrue to true
64 chars
2 lines

Boolean variables are useful for controlling the flow of a program, making decisions, or storing the state of a condition.

gistlibby LogSnag