The typescript boolean is the default and pre-defined primitive data type that can be accepted only true or false, 0 or 1 boolean type of values.
TypeScript Boolean: let isPresent:boolean = true; Note that, the boolean Boolean is different from the lower case boolean type. The upper case Boolean is an object type whereas lower case boolean is a primitive type.
In Javascript, the default value of an unassigned variable is undefined , as defined here. For example, the following typescript code: let a: string; console. log(a);
The Boolean object represents two values, either "true" or "false". If value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.
I have an object:
export class ReccurrenceModel {
fromDate: Date;
toDate: Date;
weeklyReccurrence: number;
state: State;
isMonday: boolean;
isTuesday: boolean;
isWednesday: boolean;
isThursday: boolean;
isFriday: boolean;
fromDateToReturn: Date;
toDateToReturn: Date;
}
I use it like this
if (this.reccurrenceSelected === true) {
this.reccurrence.isMonday = this.mondaySelected;
this.reccurrence.isTuesday = this.tuesdaySelected;
this.reccurrence.isWednesday = this.wednesdaySelected;
this.reccurrence.isThursday = this.thursdaySelected;
this.reccurrence.isFriday = this.fridaySelected;
}
I want to set a default value for them - false because if I do not set them in in UI, they will be undefined and I don't want that.
How to set de default value of a boolean in typescript?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With