vendredi 15 novembre 2019

How do you write this if/else statement for a boolean checker

I have these variables

    let isactive
    let istradeable = true
    let issellable = false
    let isrevocable
    let isburnable

I have an if/else that basically look at these variables and checks if they are NOT null and if it's not assign it's value to a new variable. If it is NULL set variable to true

        if (isactive == null) {
        isactive = true
    } else {
        this.isactive = isactive
    }
    if (istradeable == null) {
        istradeable = true
    } else {
        this.istradeable = istradeable
    }
    if (issellable == null) {
        issellable = true
    } else {
        this.issellable = issellable
    }
    if (isrevocable == null) {
        isrevocable = true
    } else {
        this.isrevocable = isrevocable
    }
    if (isburnable == null) {
        isburnable = true
    } else {
        this.isburnable = isburnable
    }

This works but I'm looking for a simple function or maybe a better if/else statement that does the same thing. Thanks guys!

Aucun commentaire:

Enregistrer un commentaire