Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default value of boolean typescript

Tags:

People also ask

What is default value of boolean in typescript?

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.

How do you assign a boolean value to a variable in typescript?

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.

What is the default value of number in typescript?

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);

Do booleans default to false JavaScript?

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?